Class: Gillbus::Parser
- Inherits:
-
Object
- Object
- Gillbus::Parser
- Defined in:
- lib/gillbus/helpers/parser.rb
Instance Attribute Summary collapse
-
#doc ⇒ Object
Returns the value of attribute doc.
-
#fields ⇒ Object
Returns the value of attribute fields.
-
#instance ⇒ Object
Returns the value of attribute instance.
-
#parent ⇒ Object
Returns the value of attribute parent.
Instance Method Summary collapse
-
#initialize(instance:, doc:, fields:, parent:, options: {}) ⇒ Parser
constructor
A new instance of Parser.
- #parse ⇒ Object
Constructor Details
#initialize(instance:, doc:, fields:, parent:, options: {}) ⇒ Parser
Returns a new instance of Parser.
11 12 13 14 15 16 17 |
# File 'lib/gillbus/helpers/parser.rb', line 11 def initialize(instance:, doc:, fields:, parent:, options: {}) @instance = instance @doc = doc @fields = fields @parent = parent @options = end |
Instance Attribute Details
#doc ⇒ Object
Returns the value of attribute doc.
6 7 8 |
# File 'lib/gillbus/helpers/parser.rb', line 6 def doc @doc end |
#fields ⇒ Object
Returns the value of attribute fields.
8 9 10 |
# File 'lib/gillbus/helpers/parser.rb', line 8 def fields @fields end |
#instance ⇒ Object
Returns the value of attribute instance.
7 8 9 |
# File 'lib/gillbus/helpers/parser.rb', line 7 def instance @instance end |
#parent ⇒ Object
Returns the value of attribute parent.
9 10 11 |
# File 'lib/gillbus/helpers/parser.rb', line 9 def parent @parent end |
Instance Method Details
#parse ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/gillbus/helpers/parser.rb', line 19 def parse fields.each do |name:, key:, type:, root:| raw_value = if key.is_a?(Regexp) doc.select { |k| k =~ key } elsif root doc[root] && doc[root][key] else doc[key] end value = make_one_or_many(type, raw_value) instance.send "#{name}=", value unless value.nil? end instance end |