Class: Brujula::BasicType

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parent: nil, data:, name:, as:) ⇒ BasicType

Returns a new instance of BasicType.



9
10
11
12
13
14
# File 'lib/brujula/basic_type.rb', line 9

def initialize(parent: nil, data:, name:, as:)
  @parent = parent
  @data   = data
  @name   = name
  @as     = as
end

Instance Attribute Details

#asObject (readonly)

Returns the value of attribute as.



7
8
9
# File 'lib/brujula/basic_type.rb', line 7

def as
  @as
end

#dataObject (readonly)

Returns the value of attribute data.



7
8
9
# File 'lib/brujula/basic_type.rb', line 7

def data
  @data
end

#nameObject (readonly)

Returns the value of attribute name.



7
8
9
# File 'lib/brujula/basic_type.rb', line 7

def name
  @name
end

#parentObject (readonly)

Returns the value of attribute parent.



7
8
9
# File 'lib/brujula/basic_type.rb', line 7

def parent
  @parent
end

Instance Method Details

#expandObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/brujula/basic_type.rb', line 16

def expand
  case as
  when :boolean, :number, :any
    data
  else
    base_class.new(normalized_data).tap do |instance|
      instance.extend(BasicTypeMixin)
      instance.define_singleton_method :parent do
        instance_variable_get("@parent")
      end
      instance.instance_variable_set("@name", name)
    end
  end
end