Class: Parser
- Inherits:
-
Object
- Object
- Parser
- Defined in:
- lib/apidragon/parser.rb
Instance Attribute Summary collapse
-
#output ⇒ Object
Returns the value of attribute output.
Instance Method Summary collapse
-
#initialize(field_name, qualifier_value, hash) ⇒ Parser
constructor
A new instance of Parser.
- #parse ⇒ Object
- #qualified_recurse(object) ⇒ Object
- #recurse(object) ⇒ Object
Constructor Details
#initialize(field_name, qualifier_value, hash) ⇒ Parser
Returns a new instance of Parser.
4 5 6 7 8 |
# File 'lib/apidragon/parser.rb', line 4 def initialize(field_name, qualifier_value, hash) @field_name = field_name @qualifier_value = qualifier_value @hash = hash end |
Instance Attribute Details
#output ⇒ Object
Returns the value of attribute output.
2 3 4 |
# File 'lib/apidragon/parser.rb', line 2 def output @output end |
Instance Method Details
#parse ⇒ Object
10 11 12 13 14 15 16 |
# File 'lib/apidragon/parser.rb', line 10 def parse if @qualifier_value.nil? recurse @hash else qualified_recurse @hash end end |
#qualified_recurse(object) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/apidragon/parser.rb', line 34 def qualified_recurse(object) if object.is_a? Hash if object.has_value? @qualifier_value @output = object[@field_name] else object.each_pair do |_key, value| qualified_recurse value end end elsif object.is_a? Array object.each do |element| qualified_recurse element end end end |
#recurse(object) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/apidragon/parser.rb', line 18 def recurse(object) if object.is_a? Hash if object.has_key? @field_name @output = object[@field_name] else object.each_pair do |_key, value| recurse value end end elsif object.is_a? Array object.each do |element| recurse element end end end |