Class: OmekaClient::OmekaItem
- Inherits:
-
Object
- Object
- OmekaClient::OmekaItem
- Defined in:
- lib/omeka_client/omeka-item.rb
Overview
A class to represent an item in an Omeka site
Instance Attribute Summary collapse
Instance Method Summary collapse
-
#initialize(hash) ⇒ OmekaItem
constructor
Parse the data we got from the API into handy methods.
Constructor Details
#initialize(hash) ⇒ OmekaItem
Parse the data we got from the API into handy methods. All of the data from the JSON returned by the API is available as RecursiveOpenStructs through @data. The Dublin Core and Item Type Metadata fields are also available though special methods of the form dc_title and itm_field.
22 23 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 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/omeka_client/omeka-item.rb', line 22 def initialize(hash) @data = RecursiveOpenStruct.new(hash, :recurse_over_arrays => true) # Step through the element texts separating them into Dublin Core and # Item Type Metadata elements. e is the element text hash; i is the # index of the element_text in the array of element texts. @data.element_texts.each_with_index do |e, i| if e.element_set.name == "Dublin Core" # Define a reader method that retrieves the data from this element # text in @data self.class.send(:define_method, # The name of the method will have the form "dc_title" e.element.name.downcase.gsub(/^/, 'dc_').gsub(/\s/, '_'), proc{ @data.element_texts[i].text } ) # Define a setter method that sets the data for this element text in # @ data self.class.send(:define_method, # The name of the method will have the form "dc_title=" e.element.name.downcase.gsub(/^/, 'dc_').gsub(/\s/, '_').gsub(/$/, '='), proc{ |value| @data.element_texts[i].text = value } ) elsif e.element_set.name == "Item Type Metadata" # Define a reader method that retrieves the data from this element # text in @data self.class.send(:define_method, # The name of the method will have the form "itm_field" e.element.name.downcase.gsub(/^/, 'itm_').gsub(/\s/, '_'), proc{ @data.element_texts[i].text } ) # Define a setter method that sets the data for this element text in # @ data self.class.send(:define_method, # The name of the method will have the form "itm_title=" e.element.name.downcase.gsub(/^/, 'itm_').gsub(/\s/, '_').gsub(/$/, '='), proc{ |value| @data.element_texts[i].text = value } ) end end end |
Instance Attribute Details
#data ⇒ Object
13 14 15 |
# File 'lib/omeka_client/omeka-item.rb', line 13 def data @data end |