Class: Microdata::Item
- Inherits:
-
Object
- Object
- Microdata::Item
- Defined in:
- lib/microdata/item.rb
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#properties ⇒ Object
readonly
Returns the value of attribute properties.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
-
#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.
5 6 7 8 9 10 11 12 13 |
# File 'lib/microdata/item.rb', line 5 def initialize(top_node, page_url) @top_node = top_node @type = extract_itemtype @id = extract_itemid @properties = {} @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/microdata/item.rb', line 3 def id @id end |
#properties ⇒ Object (readonly)
Returns the value of attribute properties.
3 4 5 |
# File 'lib/microdata/item.rb', line 3 def properties @properties end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
3 4 5 |
# File 'lib/microdata/item.rb', line 3 def type @type end |
Instance Method Details
#to_hash ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/microdata/item.rb', line 15 def to_hash hash = {} hash[:id] = id if id hash[:type] = type hash[:properties] = {} properties.each do |name, values| final_values = values.map do |value| if value.is_a?(Item) value.to_hash else value end end hash[:properties][name] = final_values end hash end |