Class: Hypermicrodata::Item
- Inherits:
-
Object
- Object
- Hypermicrodata::Item
- Defined in:
- lib/hypermicrodata/item.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#links ⇒ Object
readonly
Returns the value of attribute links.
-
#properties ⇒ Object
readonly
Returns the value of attribute properties.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Class Method Summary collapse
Instance Method Summary collapse
- #all_properties_and_links ⇒ Object
-
#initialize(top_node, page_url) ⇒ Item
constructor
A new instance of Item.
- #to_hash ⇒ Object
Constructor Details
#initialize(top_node, page_url) ⇒ Item
Returns a new instance of Item.
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/hypermicrodata/item.rb', line 13 def initialize(top_node, page_url) @top_node = top_node @type = extract_itemtype @id = extract_itemid @properties = {} @links = {} @page_url = page_url add_itemref_properties(@top_node) parse_elements(extract_elements(@top_node)) end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
3 4 5 |
# File 'lib/hypermicrodata/item.rb', line 3 def id @id end |
#links ⇒ Object (readonly)
Returns the value of attribute links.
3 4 5 |
# File 'lib/hypermicrodata/item.rb', line 3 def links @links end |
#properties ⇒ Object (readonly)
Returns the value of attribute properties.
3 4 5 |
# File 'lib/hypermicrodata/item.rb', line 3 def properties @properties end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
3 4 5 |
# File 'lib/hypermicrodata/item.rb', line 3 def type @type end |
Class Method Details
Instance Method Details
#all_properties_and_links ⇒ Object
53 54 55 |
# File 'lib/hypermicrodata/item.rb', line 53 def all_properties_and_links properties.values.flatten | links.values.flatten end |
#to_hash ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/hypermicrodata/item.rb', line 24 def to_hash hash = {} hash[:id] = id if id hash[:type] = type if type hash[:properties] = {} properties.each do |name, same_name_properties| final_values = same_name_properties.map do |property| if property.item property.item.to_hash else property.value end end hash[:properties][name] = final_values end hash[:links] = {} links.each do |rel, same_rel_links| final_values = same_rel_links.map do |link| if link.item link.item.to_hash else link.value end end hash[:links][rel] = final_values end hash end |