Class: Brujula::ObjectParser

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(definition:, data:, parent: :root) ⇒ ObjectParser

Returns a new instance of ObjectParser.



11
12
13
14
15
# File 'lib/brujula/object_parser.rb', line 11

def initialize(definition:, data:, parent: :root)
  @definition  = definition
  @parent      = parent
  @data        = data
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



9
10
11
# File 'lib/brujula/object_parser.rb', line 9

def args
  @args
end

#dataObject (readonly)

Returns the value of attribute data.



9
10
11
# File 'lib/brujula/object_parser.rb', line 9

def data
  @data
end

#definitionObject (readonly)

Returns the value of attribute definition.



9
10
11
# File 'lib/brujula/object_parser.rb', line 9

def definition
  @definition
end

#parentObject (readonly)

Returns the value of attribute parent.



9
10
11
# File 'lib/brujula/object_parser.rb', line 9

def parent
  @parent
end

Class Method Details

.call(definition:, data:, parent: :root) ⇒ Object



4
5
6
# File 'lib/brujula/object_parser.rb', line 4

def call(definition:, data:, parent: :root)
  new(definition: definition, data: data, parent: parent).call
end

Instance Method Details

#callObject



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

def call
  return data if not_processable_external_data?

  scheme_keys.each do |key|
    object_instance = object_builder(key).call

    definition.instance_variable_set(
      "@#{ key.accessor_name }", object_instance
    )
  end
end