Class: Reflekt::MetaBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/meta_builder.rb

Class Method Summary collapse

Class Method Details

.create(value) ⇒ Object

Create meta type for matching data type.

Parameters:

  • value (Dynamic)

    Any input or output.



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/meta_builder.rb', line 25

def self.create(value)

  meta = nil
  data_type = value.class.to_s

  case data_type
  when "Array"
    meta = ArrayMeta.new()
  when "TrueClass", "FalseClass"
    meta = BooleanMeta.new()
  when "Float"
    meta = FloatMeta.new()
  when "Integer"
    meta = IntegerMeta.new()
  when "String"
    meta = StringMeta.new()
  else
    unless value.nil?
      meta = ObjectMeta.new()
    end
  end

  unless meta.nil?
    meta.load(value)
  end

  return meta

end

.create_many(values) ⇒ Object

Create meta for multiple values.

Parameters:

  • values


60
61
62
63
64
65
66
67
68
69
70
# File 'lib/meta_builder.rb', line 60

def self.create_many(values)

  meta = []

  values.each do |value|
    meta << self.create(value)
  end

  return meta

end

.data_type_to_meta_type(value) ⇒ Object

Parameters:

  • data_type (Type)


75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/meta_builder.rb', line 75

def self.data_type_to_meta_type(value)

  data_type = value.class

  meta_types = {
    Array      => :array,
    TrueClass  => :bool,
    FalseClass => :bool,
    Float      => :float,
    Integer    => :int,
    NilClass   => :null,
    String     => :string
  }

  if meta_types.key? data_type
    return meta_types[data_type]
  elsif value.nil?
    return nil
  else
    return :object
  end

end