class ONIX::Product

Attributes

default_currency_code[RW]

default code from ONIXMessage

default_language_of_text[RW]

default LanguageCode from ONIXMessage

Public Instance Methods

available?() click to toggle source

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
available_for_country?(country) click to toggle source

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() click to toggle source

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
collateral_detail() click to toggle source

@return [CollateralDetail]

# File lib/onix/product.rb, line 109
def collateral_detail
  @collateral_detail || CollateralDetail.new
end
countries_rights() click to toggle source

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
delete?() click to toggle source

is product a deletion notification ? @return [Boolean]

# File lib/onix/product.rb, line 347
def delete?
  self.notification_type.human == "Delete"
end
descriptive_detail() click to toggle source

@return [DescriptiveDetail]

# File lib/onix/product.rb, line 114
def descriptive_detail
  @descriptive_detail || DescriptiveDetail.new
end
distributor() click to toggle source

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
distributor_gln() click to toggle source

product distributor GLN string @return [String]

# File lib/onix/product.rb, line 231
def distributor_gln
  if self.distributor
    self.distributor.gln
  end
end
distributor_name() click to toggle source

product distributor name string @return [String]

# File lib/onix/product.rb, line 223
def distributor_name
  if self.distributor
    self.distributor.name
  end
end
distributors() click to toggle source

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
excerpts() click to toggle source

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
illustrations() click to toggle source

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() click to toggle source

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() click to toggle source

imprint name string @return [String]

# File lib/onix/product.rb, line 187
def imprint_name
  if self.imprint
    self.imprint.name
  end
end
language_code_of_text() click to toggle source

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
language_name_of_text() click to toggle source

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
language_of_text() click to toggle source

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
onix_outlets_values() click to toggle source

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
paper_linking() click to toggle source

DEPRECATED see print_product instead @return [RelatedProduct]

# File lib/onix/product.rb, line 265
def paper_linking
  self.print_product
end
parse(n) click to toggle source

@!endgroup

Calls superclass method
# File lib/onix/product.rb, line 373
def parse(n)
  super
  parts.each do |part|
    part.part_of = self
  end
end
part_of_product() click to toggle source

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
price_to_be_announced?() click to toggle source

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
print_product() click to toggle source

first paper linking RelatedProduct @return [RelatedProduct]

publisher_gln() click to toggle source

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() click to toggle source

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
publishers() click to toggle source

@return (see PublishingDetail#publishers)

# File lib/onix/product.rb, line 55
def publishers
  @publishing_detail ? @publishing_detail.publishers : []
end
publishing_detail() click to toggle source

@return [PublishingDetail]

# File lib/onix/product.rb, line 119
def publishing_detail
  @publishing_detail || PublishingDetail.new
end
raw_description() click to toggle source

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() click to toggle source

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
sold_separately?() click to toggle source

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