Class: Mida::Item
- Inherits:
-
Object
- Object
- Mida::Item
- Defined in:
- lib/mida/item.rb
Overview
Class that holds a validated item
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
The Global Identifier of the item.
-
#properties ⇒ Object
readonly
A Hash representing the properties as name/values paris The values will be an array containing either
String
orMida::Item
instances. -
#type ⇒ Object
readonly
The Type of the item.
-
#vocabulary ⇒ Object
readonly
The vocabulary used to interpret this item.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(itemscope) ⇒ Item
constructor
Create a new Item object from an
Itemscope
and validates itsproperties
. -
#to_h ⇒ Object
Return a Hash representation of the form: { type: ‘example.com/vocab/review’, id: ‘urn:isbn:1-934356-08-5’, properties: {‘a name’ => ‘avalue’ } }.
- #to_s ⇒ Object
Constructor Details
#initialize(itemscope) ⇒ Item
Create a new Item object from an Itemscope
and validates its properties
- itemscope
-
The itemscope that has been parsed by
Itemscope
27 28 29 30 31 32 33 |
# File 'lib/mida/item.rb', line 27 def initialize(itemscope) @type = itemscope.type @id = itemscope.id @vocabulary = Mida::Vocabulary.find(@type) @properties = itemscope.properties validate_properties end |
Instance Attribute Details
#id ⇒ Object (readonly)
The Global Identifier of the item
16 17 18 |
# File 'lib/mida/item.rb', line 16 def id @id end |
#properties ⇒ Object (readonly)
A Hash representing the properties as name/values paris The values will be an array containing either String
or Mida::Item
instances
21 22 23 |
# File 'lib/mida/item.rb', line 21 def properties @properties end |
#type ⇒ Object (readonly)
The Type of the item
13 14 15 |
# File 'lib/mida/item.rb', line 13 def type @type end |
#vocabulary ⇒ Object (readonly)
The vocabulary used to interpret this item
10 11 12 |
# File 'lib/mida/item.rb', line 10 def vocabulary @vocabulary end |
Instance Method Details
#==(other) ⇒ Object
54 55 56 57 |
# File 'lib/mida/item.rb', line 54 def ==(other) @vocabulary == other.vocabulary && @type == other.type && @id == other.id && @properties == other.properties end |
#to_h ⇒ Object
Return a Hash representation of the form:
{ type: 'http://example.com/vocab/review',
id: 'urn:isbn:1-934356-08-5',
properties: {'a name' => 'avalue' }
}
41 42 43 44 45 46 47 48 |
# File 'lib/mida/item.rb', line 41 def to_h # Only fill hash with non-nil values hash = {} @type and hash[:type] = @type @id and hash[:id] = @id @properties.any? and hash[:properties] = properties_to_h(@properties) hash end |
#to_s ⇒ Object
50 51 52 |
# File 'lib/mida/item.rb', line 50 def to_s to_h.to_s end |