Class: Swicky::ExhibitJson::Item
- Defined in:
- lib/swicky/exhibit_json/item.rb
Overview
An item in the Exhibit JSON. Each item belongs to a collection.
Instance Attribute Summary collapse
-
#collection ⇒ Object
readonly
Returns the value of attribute collection.
-
#element ⇒ Object
readonly
Returns the value of attribute element.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
- #add_properties(properties) ⇒ Object
- #id ⇒ Object
-
#initialize(element, collection) ⇒ Item
constructor
A new instance of Item.
- #label ⇒ Object
- #to_json(*a) ⇒ Object
- #uri ⇒ Object
Constructor Details
#initialize(element, collection) ⇒ Item
Returns a new instance of Item.
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/swicky/exhibit_json/item.rb', line 12 def initialize(element, collection) raise(ArgumentError, "Element must have an URI, was a #{element.class.name}: #{element.inspect}") unless(element.respond_to?(:uri)) raise(ArgumentError, "Element must always belong to a collection") unless(collection) @original_properties = {} @element = element @properties = {} @collection = collection create_label! @properties['uri'] = self.uri @properties['id'] = @collection.make_id(self) @properties['hash'] = ('h_' << Digest::MD5.hexdigest(self.uri)) end |
Instance Attribute Details
#collection ⇒ Object (readonly)
Returns the value of attribute collection.
9 10 11 |
# File 'lib/swicky/exhibit_json/item.rb', line 9 def collection @collection end |
#element ⇒ Object (readonly)
Returns the value of attribute element.
9 10 11 |
# File 'lib/swicky/exhibit_json/item.rb', line 9 def element @element end |
Instance Method Details
#[](key) ⇒ Object
37 38 39 |
# File 'lib/swicky/exhibit_json/item.rb', line 37 def [](key) @properties[key] end |
#[]=(key, value) ⇒ Object
41 42 43 |
# File 'lib/swicky/exhibit_json/item.rb', line 41 def []=(key, value) @properties[key] = value end |
#add_properties(properties) ⇒ Object
45 46 47 48 49 50 |
# File 'lib/swicky/exhibit_json/item.rb', line 45 def add_properties(properties) @original_properties = properties create_label! create_types! create_properties! end |
#id ⇒ Object
29 30 31 |
# File 'lib/swicky/exhibit_json/item.rb', line 29 def id @properties['id'] end |
#label ⇒ Object
33 34 35 |
# File 'lib/swicky/exhibit_json/item.rb', line 33 def label @properties['label'] end |
#to_json(*a) ⇒ Object
52 53 54 |
# File 'lib/swicky/exhibit_json/item.rb', line 52 def to_json(*a) @properties.to_json(*a) end |
#uri ⇒ Object
25 26 27 |
# File 'lib/swicky/exhibit_json/item.rb', line 25 def uri @element.uri.to_s end |