Class: FDDB::Item
Instance Attribute Summary collapse
-
#item ⇒ Object
readonly
Returns the value of attribute item.
Class Method Summary collapse
Instance Method Summary collapse
- #check_item(xml_string) ⇒ Object
-
#get_ingredients(query = nil) ⇒ Object
returns the ingredients to an given element available filters are (:minerals, :vitamines, :general).
Methods included from Parser
Instance Attribute Details
#item ⇒ Object (readonly)
Returns the value of attribute item.
5 6 7 |
# File 'lib/fddb/item.rb', line 5 def item @item end |
Class Method Details
.init(xml_string) ⇒ Object
8 9 10 11 12 |
# File 'lib/fddb/item.rb', line 8 def self.init (xml_string) element = Item.new xml_string return nil if element.item['error'] element end |
Instance Method Details
#check_item(xml_string) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/fddb/item.rb', line 14 def check_item (xml_string) return xml_string if xml_string.class == Hash # if item is already a hash begin item = parse xml_string throw "Error - #{item['error']}" unless item['error'].nil? response = item['result']['item'] if xml_string.class == String rescue Exception => e puts e response = item end response end |
#get_ingredients(query = nil) ⇒ Object
returns the ingredients to an given element available filters are (:minerals, :vitamines, :general)
32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/fddb/item.rb', line 32 def get_ingredients (query = nil) return @item['data'] if query.nil? case query when :minerals search_ingredient 'm' when :vitamins search_ingredient 'v' when :general search_ingredient '(?!(a|l)).' else nil end end |