class Cacofonix::APAProduct
Public Instance Methods
add a BIC subject code to the product
# File lib/cacofonix/wrappers/apa_product.rb, line 167 def add_bic_subject(code) add_subject code, "12" end
add a BISAC subject code to the product
# File lib/cacofonix/wrappers/apa_product.rb, line 178 def add_bisac_subject(code) add_subject code, "10" end
set a new contributor to this product str should be the contributors name inverted (Healy, James)
# File lib/cacofonix/wrappers/apa_product.rb, line 150 def add_contributor(str, role = "A01") contrib = ::Cacofonix::Contributor.new contrib.sequence_number = product.contributors.size + 1 contrib.contributor_role = role contrib.person_name_inverted = str product.contributors << contrib end
# File lib/cacofonix/wrappers/apa_product.rb, line 536 def agent_name reps = product.market_representations.first return nil if reps.nil? reps.agent_name end
# File lib/cacofonix/wrappers/apa_product.rb, line 542 def agent_name=(value) reps = product.market_representations.first if reps.nil? reps = Cacofonix::MarketRepresentation.new product.market_representations << reps end reps.agent_name = value.to_s end
return an array of BIC subjects for this title could be version 1 or version 2, most ONIX files don't specifiy
# File lib/cacofonix/wrappers/apa_product.rb, line 161 def bic_subjects subjects = product.subjects.select { |sub| sub.subject_scheme_id.to_i == 12 } subjects.collect { |sub| sub.subject_code} end
return an array of BISAC subjects for this title
# File lib/cacofonix/wrappers/apa_product.rb, line 172 def bisac_subjects subjects = product.subjects.select { |sub| sub.subject_scheme_id.to_i == 10 } subjects.collect { |sub| sub.subject_code} end
retrieve an array of all contributors
# File lib/cacofonix/wrappers/apa_product.rb, line 144 def contributors product.contributors.collect { |contrib| contrib.person_name_inverted || contrib.person_name} end
retrieve the url to the product cover image
# File lib/cacofonix/wrappers/apa_product.rb, line 183 def cover_url media_file(4).try(:media_file_link) end
set the url to the product cover image
# File lib/cacofonix/wrappers/apa_product.rb, line 188 def cover_url=(url) # 4 - cover image # 1 - URI media_file_set(4,1,url) end
retrieve the url to the high quality product cover image
# File lib/cacofonix/wrappers/apa_product.rb, line 195 def cover_url_hq media_file(6).try(:media_file_link) end
set the url to the high quality product cover image
# File lib/cacofonix/wrappers/apa_product.rb, line 200 def cover_url_hq=(url) # 6 - hq cover image # 1 - URI media_file_set(6,1,url) end
retrieve the current EAN
# File lib/cacofonix/wrappers/apa_product.rb, line 28 def ean identifier(3).try(:id_value) end
set a new EAN
# File lib/cacofonix/wrappers/apa_product.rb, line 33 def ean=(isbn) identifier_set(3, isbn) end
retrieve the height of the product
If APAProduct#measurement_system
is metric, these will be in mm, otherwise they will be in inches.
# File lib/cacofonix/wrappers/apa_product.rb, line 449 def height # TODO: auto unit conversion measurement(1).try(:measurement) end
set the height of the book
If APAProduct#measurement_system
is metric, this should be in mm, otherwise it will be in inches.
# File lib/cacofonix/wrappers/apa_product.rb, line 459 def height=(value) if measurement_system == :metric measurement_set(1,value, "mm") elsif measurement_system == :imperial measurement_set(1,value, "in") end end
retrieve the imprint
# File lib/cacofonix/wrappers/apa_product.rb, line 249 def imprint composite = product.imprints.first composite ? composite.imprint_name : nil end
set a new imprint
# File lib/cacofonix/wrappers/apa_product.rb, line 255 def imprint=(str) composite = product.imprints.first if composite.nil? composite = Cacofonix::Imprint.new product.imprints << composite end composite.imprint_name = str end
retrieve the current ISBN 10
# File lib/cacofonix/wrappers/apa_product.rb, line 48 def isbn10 identifier(2).try(:id_value) end
set a new ISBN 10
# File lib/cacofonix/wrappers/apa_product.rb, line 53 def isbn10=(isbn) identifier_set(2, isbn) end
retrieve the current ISBN 13
# File lib/cacofonix/wrappers/apa_product.rb, line 58 def isbn13 identifier(15).try(:id_value) end
set a new ISBN 13
# File lib/cacofonix/wrappers/apa_product.rb, line 63 def isbn13=(isbn) identifier_set(15, isbn) end
retrieve the long description
# File lib/cacofonix/wrappers/apa_product.rb, line 239 def long_description other_text(3).try(:text) end
set the long description
# File lib/cacofonix/wrappers/apa_product.rb, line 244 def long_description=(t) other_text_set(3,t) end
retrieve the main description
# File lib/cacofonix/wrappers/apa_product.rb, line 219 def main_description other_text(1).try(:text) end
set the main description
# File lib/cacofonix/wrappers/apa_product.rb, line 224 def main_description=(t) other_text_set(1,t) end
# File lib/cacofonix/wrappers/apa_product.rb, line 551 def market_country reps = product.market_representations.first return nil if reps.nil? reps.market_country end
# File lib/cacofonix/wrappers/apa_product.rb, line 557 def market_country=(value) reps = product.market_representations.first if reps.nil? reps = Cacofonix::MarketRepresentation.new product.market_representations << reps end reps.market_country = value.to_s end
# File lib/cacofonix/wrappers/apa_product.rb, line 566 def market_publishing_status reps = product.market_representations.first return nil if reps.nil? reps.market_publishing_status end
# File lib/cacofonix/wrappers/apa_product.rb, line 572 def market_publishing_status=(value) reps = product.market_representations.first if reps.nil? reps = Cacofonix::MarketRepresentation.new product.market_representations << reps end reps.market_publishing_status = value.to_i end
# File lib/cacofonix/wrappers/apa_product.rb, line 15 def measurement_system @measurement_system ||= :metric end
# File lib/cacofonix/wrappers/apa_product.rb, line 19 def measurement_system=(value) if value == :metric || value == :imperial @measurement_system = value else raise ArgumentError, "#{value} is not a recognised measurement system" end end
retrieve the number in stock
# File lib/cacofonix/wrappers/apa_product.rb, line 363 def on_hand supply = find_or_create_supply_detail composite = supply.stock.first if composite.nil? composite = Cacofonix::Stock.new supply.stock << composite end composite.on_hand end
set a new in stock quantity
# File lib/cacofonix/wrappers/apa_product.rb, line 374 def on_hand=(num) supply = find_or_create_supply_detail composite = supply.stock.first if composite.nil? composite = Cacofonix::Stock.new supply.stock << composite end composite.on_hand = num end
retrieve the number on order
# File lib/cacofonix/wrappers/apa_product.rb, line 385 def on_order supply = find_or_create_supply_detail composite = supply.stock.first if composite.nil? composite = Cacofonix::Stock.new supply.stock << composite end composite.on_order end
set a new on order quantity
# File lib/cacofonix/wrappers/apa_product.rb, line 396 def on_order=(num) supply = find_or_create_supply_detail composite = supply.stock.first if composite.nil? composite = Cacofonix::Stock.new supply.stock << composite end composite.on_order = num end
retrieve the supplier phone number
# File lib/cacofonix/wrappers/apa_product.rb, line 407 def pack_quantity composite = product.supply_details.first composite.nil? ? nil : composite.pack_quantity end
set a new supplier phone number
# File lib/cacofonix/wrappers/apa_product.rb, line 413 def pack_quantity=(val) composite = find_or_create_supply_detail composite.pack_quantity = val.to_i end
just get the first price we can find, regardless of the type. useful as a backup for reading files from that don't contain a type
# File lib/cacofonix/wrappers/apa_product.rb, line 440 def price price_get(nil).try(:price_amount) end
retrieve the product availability code
# File lib/cacofonix/wrappers/apa_product.rb, line 351 def product_availability composite = product.supply_details.first composite.nil? ? nil : composite.product_availability end
set a new product availability
# File lib/cacofonix/wrappers/apa_product.rb, line 357 def product_availability=(num) composite = find_or_create_supply_detail composite.product_availability = num end
retrieve the proprietary ID
# File lib/cacofonix/wrappers/apa_product.rb, line 38 def proprietary_id identifier(1).tr(:id_value) end
set a new proprietary ID
# File lib/cacofonix/wrappers/apa_product.rb, line 43 def proprietary_id=(isbn) identifier_set(1, isbn) end
retrieve the publisher
# File lib/cacofonix/wrappers/apa_product.rb, line 265 def publisher publisher_get(1).try(:publisher_name) end
set a new publisher
# File lib/cacofonix/wrappers/apa_product.rb, line 270 def publisher=(str) publisher_set(1, str) end
retrieve the current publisher website for this particular product
# File lib/cacofonix/wrappers/apa_product.rb, line 124 def publisher_website website(2).try(:website_link) end
set a new publisher website for this particular product
# File lib/cacofonix/wrappers/apa_product.rb, line 129 def publisher_website=(str) website_set(2, str) end
retrieve the rrp excluding any sales tax
# File lib/cacofonix/wrappers/apa_product.rb, line 419 def rrp_exc_sales_tax price_get(1).try(:price_amount) end
set the rrp excluding any sales tax
# File lib/cacofonix/wrappers/apa_product.rb, line 424 def rrp_exc_sales_tax=(num) price_set(1, num) end
retrieve the rrp including any sales tax
# File lib/cacofonix/wrappers/apa_product.rb, line 429 def rrp_inc_sales_tax price_get(2).try(:price_amount) end
set the rrp including any sales tax
# File lib/cacofonix/wrappers/apa_product.rb, line 434 def rrp_inc_sales_tax=(num) price_set(2, num) end
retrieve the sales restriction type
# File lib/cacofonix/wrappers/apa_product.rb, line 275 def sales_restriction_type composite = product.sales_restrictions.first composite.nil? ? nil : composite.imprint_name end
set a new sales restriction type
# File lib/cacofonix/wrappers/apa_product.rb, line 281 def sales_restriction_type=(type) composite = product.sales_restrictions.first if composite.nil? composite = Cacofonix::SalesRestriction.new product.sales_restrictions << composite end composite.sales_restriction_type = type end
# File lib/cacofonix/wrappers/apa_product.rb, line 109 def series composite = product.series.first composite.try(:title_of_series) end
# File lib/cacofonix/wrappers/apa_product.rb, line 114 def series=(val) composite = product.series.first if composite.nil? composite = Cacofonix::Series.new product.series << composite end composite.title_of_series = val.to_s end
retrieve the short description
# File lib/cacofonix/wrappers/apa_product.rb, line 229 def short_description other_text(2).try(:text) end
set the short description
# File lib/cacofonix/wrappers/apa_product.rb, line 234 def short_description=(t) other_text_set(2,t) end
retrieve the current subtitle
# File lib/cacofonix/wrappers/apa_product.rb, line 89 def subtitle composite = product.titles.first if composite.nil? nil else composite.subtitle end end
set a new subtitle
# File lib/cacofonix/wrappers/apa_product.rb, line 99 def subtitle=(str) composite = product.titles.first if composite.nil? composite = Cacofonix::Title.new composite.title_type = 1 product.titles << composite end composite.subtitle = str end
retrieve the supplier email address
# File lib/cacofonix/wrappers/apa_product.rb, line 327 def supplier_email composite = product.supply_details.first composite.nil? ? nil : composite.email_address end
set a new supplier email address
# File lib/cacofonix/wrappers/apa_product.rb, line 333 def supplier_email=(str) composite = find_or_create_supply_detail composite.email_address = str end
retrieve the supplier fax number
# File lib/cacofonix/wrappers/apa_product.rb, line 315 def supplier_fax composite = product.supply_details.first composite.nil? ? nil : composite.fax_number end
set a new supplier fax number
# File lib/cacofonix/wrappers/apa_product.rb, line 321 def supplier_fax=(str) composite = find_or_create_supply_detail composite.fax_number = str end
retrieve the supplier name
# File lib/cacofonix/wrappers/apa_product.rb, line 291 def supplier_name composite = product.supply_details.first composite.nil? ? nil : composite.supplier_name end
set a new supplier name
# File lib/cacofonix/wrappers/apa_product.rb, line 297 def supplier_name=(str) composite = find_or_create_supply_detail composite.supplier_name = str end
retrieve the supplier phone number
# File lib/cacofonix/wrappers/apa_product.rb, line 303 def supplier_phone composite = product.supply_details.first composite.nil? ? nil : composite.telephone_number end
set a new supplier phone number
# File lib/cacofonix/wrappers/apa_product.rb, line 309 def supplier_phone=(str) composite = find_or_create_supply_detail composite.telephone_number = str end
retrieve the current supplier website for this particular product
# File lib/cacofonix/wrappers/apa_product.rb, line 134 def supplier_website website(12).try(:website_link) end
set a new supplier website for this particular product
# File lib/cacofonix/wrappers/apa_product.rb, line 139 def supplier_website=(str) website_set(12, str) end
retrieve the supply country code
# File lib/cacofonix/wrappers/apa_product.rb, line 339 def supply_country composite = product.supply_details.first composite.nil? ? nil : composite.supply_to_country end
set a new supply country code
# File lib/cacofonix/wrappers/apa_product.rb, line 345 def supply_country=(str) composite = find_or_create_supply_detail composite.supply_to_country = str end
retrieve the thickness of the product
If APAProduct#measurement_system
is metric, these will be in mm, otherwise they will be in inches.
# File lib/cacofonix/wrappers/apa_product.rb, line 518 def thickness # TODO: auto unit conversion measurement(3).try(:measurement) end
set the thickness of the product
If APAProduct#measurement_system
is metric, this should be in mm, otherwise it will be in inches.
# File lib/cacofonix/wrappers/apa_product.rb, line 528 def thickness=(value) if measurement_system == :metric measurement_set(3,value, "mm") elsif measurement_system == :imperial measurement_set(3,value, "in") end end
retrieve the url to the product thumbnail
# File lib/cacofonix/wrappers/apa_product.rb, line 207 def thumbnail_url media_file(7).try(:media_file_link) end
set the url to the product cover image
# File lib/cacofonix/wrappers/apa_product.rb, line 212 def thumbnail_url=(url) # 7 - thumbnail image # 1 - URI media_file_set(7,1,url) end
retrieve the current title
# File lib/cacofonix/wrappers/apa_product.rb, line 68 def title composite = product.titles.first if composite.nil? nil else composite.title_text || composite.title_without_prefix end end
set a new title
# File lib/cacofonix/wrappers/apa_product.rb, line 78 def title=(str) composite = product.titles.first if composite.nil? composite = Cacofonix::Title.new composite.title_type = 1 product.titles << composite end composite.title_text = str end
retrieve the weight of the product
If APAProduct#measurement_system
is metric, these will be in grams, otherwise they will be in ounces.
# File lib/cacofonix/wrappers/apa_product.rb, line 495 def weight # TODO: auto unit conversion measurement(8).try(:measurement) end
set the weight of the product
If APAProduct#measurement_system
is metric, this should be in grams, otherwise it will be in ounces.
# File lib/cacofonix/wrappers/apa_product.rb, line 505 def weight=(value) if measurement_system == :metric measurement_set(8,value, "gr") elsif measurement_system == :imperial measurement_set(8,value, "oz") end end
retrieve the width of the product
If APAProduct#measurement_system
is metric, these will be in mm, otherwise they will be in inches.
# File lib/cacofonix/wrappers/apa_product.rb, line 472 def width # TODO: auto unit conversion measurement(2).try(:measurement) end
set the width of the product
If APAProduct#measurement_system
is metric, this should be in mm, otherwise it will be in inches.
# File lib/cacofonix/wrappers/apa_product.rb, line 482 def width=(value) if measurement_system == :metric measurement_set(2,value, "mm") elsif measurement_system == :imperial measurement_set(2,value, "in") end end
Private Instance Methods
add a new subject to this product str should be the subject code type should be the code for the subject scheme you're using. See ONIX codelist 27. 12 is BIC
# File lib/cacofonix/wrappers/apa_product.rb, line 587 def add_subject(str, type = "12") subject = ::Cacofonix::Subject.new subject.subject_scheme_id = type.to_i subject.subject_code = str product.subjects << subject end
# File lib/cacofonix/wrappers/apa_product.rb, line 594 def find_or_create_supply_detail composite = product.supply_details.first if composite.nil? composite = Cacofonix::SupplyDetail.new product.supply_details << composite end composite end
retrieve the value of a particular ID
# File lib/cacofonix/wrappers/apa_product.rb, line 604 def identifier(type) product.product_identifiers.find { |id| id.product_id_type == type } end
set the value of a particular ID
# File lib/cacofonix/wrappers/apa_product.rb, line 609 def identifier_set(type, value) isbn_id = identifier(type) # create a new isbn record if we need to if isbn_id.nil? isbn_id = Cacofonix::ProductIdentifier.new isbn_id.product_id_type = type product.product_identifiers << isbn_id end isbn_id.id_value = value end
retrieve the value of a particular measurement
# File lib/cacofonix/wrappers/apa_product.rb, line 623 def measurement(type) product.measurements.find { |m| m.measure_type_code == type } end
set the value of a particular measurement
# File lib/cacofonix/wrappers/apa_product.rb, line 628 def measurement_set(type, value, unit) measure = measurement(type) # create a new isbn record if we need to if measure.nil? measure = Cacofonix::Measure.new measure.measure_type_code = type product.measurements << measure end # store the new value measure.measurement = value measure.measure_unit_code = unit.to_s end
retrieve the value of a particular media file
# File lib/cacofonix/wrappers/apa_product.rb, line 644 def media_file(type) product.media_files.find { |m| m.media_file_type_code == type } end
set the value of a particular ID
# File lib/cacofonix/wrappers/apa_product.rb, line 649 def media_file_set(type, link_type, value) media = media_file(type) # create a new isbn record if we need to if media.nil? media = Cacofonix::MediaFile.new media.media_file_type_code = type media.media_file_link_type_code = link_type product.media_files << media end # store the new value media.media_file_link = value.to_s end
retrieve the value of a particular other text value
# File lib/cacofonix/wrappers/apa_product.rb, line 711 def other_text(type) product.text.find { |t| t.text_type_code == type } end
set the value of a particular other text value
# File lib/cacofonix/wrappers/apa_product.rb, line 716 def other_text_set(type, value) text = other_text(type) if text.nil? text = Cacofonix::OtherText.new text.text_type_code = type product.text << text end # store the new value text.text = value.to_s end
retrieve the value of a particular price
# File lib/cacofonix/wrappers/apa_product.rb, line 665 def price_get(type) supply = find_or_create_supply_detail if type.nil? supply.prices.first else supply.prices.find { |p| p.price_type_code == type } end end
set the value of a particular price
# File lib/cacofonix/wrappers/apa_product.rb, line 675 def price_set(type, num) p = price_get(type) # create a new isbn record if we need to if p.nil? supply = find_or_create_supply_detail p = Cacofonix::Price.new p.price_type_code = type supply.prices << p end # store the new value p.price_amount = num end
retrieve the value of a particular publisher
# File lib/cacofonix/wrappers/apa_product.rb, line 691 def publisher_get(type) product.publishers.find { |pub| pub.publishing_role == type } end
set the value of a particular ID
# File lib/cacofonix/wrappers/apa_product.rb, line 696 def publisher_set(type, value) pub = publisher_get(type) # create a new isbn record if we need to if pub.nil? pub = Cacofonix::Publisher.new pub.publishing_role = type product.publishers << pub end # store the new value pub.publisher_name = value.to_s end
retrieve the value of a particular website
# File lib/cacofonix/wrappers/apa_product.rb, line 730 def website(type) product.websites.find { |site| site.website_role == type } end
set the value of a particular website
# File lib/cacofonix/wrappers/apa_product.rb, line 735 def website_set(type, value) site = website(type) # create a new website record if we need to if site.nil? site = Cacofonix::Website.new site.website_role = type product.websites << site end site.website_link = value.to_s end