class ONIX::Product
Attributes
default code from ONIXMessage
default LanguageCode
from ONIXMessage
Public Instance Methods
is product available ? @return [Boolean]
# File lib/onix/product.rb, line 326 def available? self.available_product_supplies.length > 0 and not self.delete? end
is product available for given country
? @return [Boolean]
# File lib/onix/product.rb, line 332 def available_for_country?(country) self.supplies_for_country(country).select { |s| s[:available] }.length > 0 and self.available? end
available product supplies @return [Array<ProductSupply>]
# File lib/onix/product.rb, line 320 def available_product_supplies @product_supplies.select { |product_supply| product_supply.available? } end
@return [CollateralDetail]
# File lib/onix/product.rb, line 109 def collateral_detail @collateral_detail || CollateralDetail.new end
product countries rights string array @return [Array<String>]
# File lib/onix/product.rb, line 271 def countries_rights countries = [] if @publishing_detail countries += @publishing_detail.sales_rights.map { |sale_right| sale_right.territory.countries }.flatten.uniq end if @product_supplies countries += @product_supplies.map { |product_supply| product_supply.markets.map { |market| market.territory.countries }.flatten }.flatten.uniq end countries.uniq end
is product a deletion notification ? @return [Boolean]
# File lib/onix/product.rb, line 347 def delete? self.notification_type.human == "Delete" end
@return [DescriptiveDetail]
# File lib/onix/product.rb, line 114 def descriptive_detail @descriptive_detail || DescriptiveDetail.new end
product distributor name @return [String]
# File lib/onix/product.rb, line 209 def distributor if self.distributors.length > 0 if self.distributors.length == 1 self.distributors.first else raise ExpectsOneButHasSeveral, self.distributors.map(&:name) end else nil end end
product distributor GLN string @return [String]
# File lib/onix/product.rb, line 231 def distributor_gln if self.distributor self.distributor.gln end end
product distributor name string @return [String]
# File lib/onix/product.rb, line 223 def distributor_name if self.distributor self.distributor.name end end
product distributors names @return [Array<String>]
# File lib/onix/product.rb, line 203 def distributors @product_supplies.map { |ps| ps.distributors }.flatten.uniq { |d| d.name } end
all excerpts
# File lib/onix/product.rb, line 304 def excerpts return [] unless @collateral_detail && @collateral_detail.supporting_resources @collateral_detail.supporting_resources.sample_content.human_code_match(:resource_mode, ["Text", "MultiMode"]).map do |resource| { :url => resource.versions.last.links.first.strip, :form => resource.versions.last.form.human, :md5 => resource.versions.last.md5_hash, :format_code => resource.versions.last.file_format, :updated_at => resource.versions.last.last_updated_utc } end end
all images
# File lib/onix/product.rb, line 287 def illustrations return [] unless @collateral_detail && @collateral_detail.supporting_resources @collateral_detail.supporting_resources.image.map do |image_resource| { :url => image_resource.versions.last.links.first.strip, :type => image_resource.type.human, :width => image_resource.versions.last.image_width, :height => image_resource.versions.last.image_height, :caption => image_resource.caption, :format_code => image_resource.versions.last.file_format, :updated_at => image_resource.versions.last.last_updated_utc } end end
imprint GLN string @return [String]
# File lib/onix/product.rb, line 195 def imprint_gln if self.imprint self.imprint.gln end end
imprint name string @return [String]
# File lib/onix/product.rb, line 187 def imprint_name if self.imprint self.imprint.name end end
product language code string of text (eg: fre) @return [String]
# File lib/onix/product.rb, line 131 def language_code_of_text if self.language_of_text self.language_of_text.code end end
product language name string of text (eg: French) @return [String]
# File lib/onix/product.rb, line 139 def language_name_of_text if self.language_of_text self.language_of_text.human end end
product LanguageCode
of text @return [String]
# File lib/onix/product.rb, line 125 def language_of_text @descriptive_detail.language_of_text || @default_language_of_text end
List of ONIX
outlets values @return [Array<String>]
# File lib/onix/product.rb, line 353 def onix_outlets_values if @publishing_detail @publishing_detail.sales_rights.map { |sales_right| sales_right.sales_restrictions.select { |sales_restriction| (!sales_restriction.start_date or sales_restriction.start_date <= Date.today) and (!sales_restriction.end_date or sales_restriction.end_date >= Date.today) }.map { |sale_right| sale_right.sales_outlets.select { |sale_outlet| sale_outlet.identifier and sale_outlet.identifier.type.human == "OnixRetailSalesOutletIdCode" }.map { |sale_outlet| sale_outlet.identifier.value } } }.flatten else [] end end
DEPRECATED see print_product
instead @return [RelatedProduct]
# File lib/onix/product.rb, line 265 def paper_linking self.print_product end
@!endgroup
# File lib/onix/product.rb, line 373 def parse(n) super parts.each do |part| part.part_of = self end end
first part RelatedProduct
@return [RelatedProduct]
# File lib/onix/product.rb, line 249 def part_of_product if @related_material @related_material.part_of_products.first end end
is product price to be announced ? @return [Boolean]
# File lib/onix/product.rb, line 338 def price_to_be_announced? unless self.product_supplies.empty? || self.product_supplies.first.supply_details.empty? unpriced_item_type = self.product_supplies.first.supply_details.first.unpriced_item_type end unpriced_item_type ? unpriced_item_type.human == "PriceToBeAnnounced" : false end
first paper linking RelatedProduct
@return [RelatedProduct]
# File lib/onix/product.rb, line 257 def print_product if @related_material @related_material.print_products.first end end
publisher GLN string, nil if multiple publishers are found @return [String]
# File lib/onix/product.rb, line 179 def publisher_gln if self.publishers.length == 1 self.publisher.gln end end
publisher name string, if multiple publishers are found, then they are concatenated with “ / ” @return [String]
# File lib/onix/product.rb, line 171 def publisher_name if self.publishers.length > 0 self.publishers.map { |p| p.name }.join(" / ") end end
@return (see PublishingDetail#publishers)
# File lib/onix/product.rb, line 55 def publishers @publishing_detail ? @publishing_detail.publishers : [] end
@return [PublishingDetail]
# File lib/onix/product.rb, line 119 def publishing_detail @publishing_detail || PublishingDetail.new end
raw book description string without HTML @return [String]
# File lib/onix/product.rb, line 163 def raw_description if self.description Helper.strip_html(self.description).gsub(/\s+/, " ").strip end end
raw file description string without HTML @return [String]
# File lib/onix/product.rb, line 155 def raw_file_description if @descriptive_detail.file_description Helper.strip_html(@descriptive_detail.file_description).gsub(/\s+/, " ").strip end end
product can be sold separately ? @return [Boolean]
# File lib/onix/product.rb, line 147 def sold_separately? @product_supplies.map { |product_supply| product_supply.supply_details.map { |supply_detail| supply_detail.sold_separately? }.flatten }.flatten.uniq.first end