Class: TitlePage::Product

Inherits:
Object
  • Object
show all
Defined in:
lib/titlepage/utils.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#contributorsObject

Returns the value of attribute contributors.



183
184
185
# File 'lib/titlepage/utils.rb', line 183

def contributors
  @contributors
end

#product_identifiersObject

Returns the value of attribute product_identifiers.



181
182
183
# File 'lib/titlepage/utils.rb', line 181

def product_identifiers
  @product_identifiers
end

#supply_detailObject

Returns the value of attribute supply_detail.



184
185
186
# File 'lib/titlepage/utils.rb', line 184

def supply_detail
  @supply_detail
end

#titleObject

Returns the value of attribute title.



182
183
184
# File 'lib/titlepage/utils.rb', line 182

def title
  @title
end

Class Method Details

.from_xml(node) ⇒ Object



186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
# File 'lib/titlepage/utils.rb', line 186

def self.from_xml(node)
  return nil if node.nil?

  product = self.new

  product.product_identifiers = node.xpath("//Product/ProductIdentifiers/item").map do |node|
    TitlePage::ProductIdentifier.from_xml(node)
  end

  title_node = node.xpath("//Product/Title")
  product.title = TitlePage::Title.from_xml(title_node)

  product.contributors = node.xpath("//Product/Contributors/item").map do |node|
    TitlePage::Contributor.from_xml(node)
  end

  sd_node = node.xpath("//Product/SupplyDetail")
  product.supply_detail = TitlePage::SupplyDetail.from_xml(sd_node)

  product
end

Instance Method Details

#to_hashObject

return a simple hash representation of this product



210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
# File 'lib/titlepage/utils.rb', line 210

def to_hash
  {
    :ean      => self.product_identifiers.first.id_value,
    :title    => self.title.title_text,
    :subtitle    => self.title.subtitle,
    :contributors => self.contributors.collect { |c| c.person_name_inverted },
    :supplier => self.supply_detail.supplier_name,
    :supplier_role => self.supply_detail.supplier_role,
    :price    => self.supply_detail.price.price_amount.to_s("F").to_f,
    :availability => self.supply_detail.product_availability,
    :on_hand  => self.supply_detail.stock.on_hand,
    :on_order  => self.supply_detail.stock.on_order,
    :expected_ship_date => self.supply_detail.expected_ship_date,
    :pack_quantity => self.supply_detail.pack_quantity
  }
end

#to_yamlObject

return a simple YAML representation of this product



229
230
231
# File 'lib/titlepage/utils.rb', line 229

def to_yaml
  YAML.dump(to_hash)
end