Module: Eve::API::Response::Result
- Included in:
- Eve::API::Response, Row
- Defined in:
- lib/eve/api/response/result.rb
Instance Method Summary collapse
- #[](name) ⇒ Object
- #all_fields ⇒ Object
- #delegate_to_child(field_name, node) ⇒ Object
- #delegate_to_rowset(field_name, rowset) ⇒ Object
- #literal_value_for(str) ⇒ Object
- #parse_children(node) ⇒ Object
- #to_hash ⇒ Object
- #to_yaml(*args) ⇒ Object
Instance Method Details
#[](name) ⇒ Object
73 74 75 |
# File 'lib/eve/api/response/result.rb', line 73 def [](name) send name end |
#all_fields ⇒ Object
2 3 4 |
# File 'lib/eve/api/response/result.rb', line 2 def all_fields @all_fields ||= [] end |
#delegate_to_child(field_name, node) ⇒ Object
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 54 55 56 57 58 |
# File 'lib/eve/api/response/result.rb', line 28 def delegate_to_child(field_name, node) all_fields << field_name.underscore klass = (class << self; self; end) if !node.children.empty? && node.children.reject { |c| c.text? }.empty? # this seems less correct but specs pass this way if node.name != 'error' child = literal_value_for node.content.strip else child = Eve::API::Response::Row.new node end # if node.attributes.empty? # # node contains only text # child = literal_value_for node.content.strip # else # child = Eve::API::Response::Row.new node # end else child = Eve::API::Response::Row.new node end klass.module_eval do define_method field_name do child end if field_name.underscore != field_name alias_method field_name.underscore, field_name end end child end |
#delegate_to_rowset(field_name, rowset) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/eve/api/response/result.rb', line 6 def delegate_to_rowset(field_name, rowset) all_fields << field_name.underscore klass = (class << self; self; end) rowset = Eve::API::Response::Rowset.new rowset klass.module_eval do define_method field_name do rowset end if field_name.underscore != field_name alias_method field_name.underscore, field_name end end rowset end |
#literal_value_for(str) ⇒ Object
22 23 24 25 26 |
# File 'lib/eve/api/response/result.rb', line 22 def literal_value_for(str) YAML::load str rescue (defined?(Psych::SyntaxError) ? Psych::SyntaxError : StandardError) str end |
#parse_children(node) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/eve/api/response/result.rb', line 60 def parse_children(node) node.children.each do |child| next if child.text? case child.name when 'rowset' rowset = delegate_to_rowset child.attributes['name'].value, child rowsets << rowset else delegate_to_child child.name, child end end end |
#to_hash ⇒ Object
77 78 79 80 81 82 |
# File 'lib/eve/api/response/result.rb', line 77 def to_hash all_fields.inject({}) do |hash, field_name| hash[field_name] = self[field_name] hash end end |
#to_yaml(*args) ⇒ Object
84 85 86 |
# File 'lib/eve/api/response/result.rb', line 84 def to_yaml(*args) to_hash.to_yaml(*args) end |