Class: ONIX::SLProduct
- Inherits:
-
APAProduct
- Object
- SimpleProduct
- APAProduct
- ONIX::SLProduct
- Defined in:
- lib/onix/sl_product.rb
Instance Method Summary collapse
-
#add_language(str, role = "1", country = "US") ⇒ Object
set a new language to this product str should be the languages name code (US).
- #add_price(amount, *args) ⇒ Object
-
#add_work_identifier(value, type = 1) ⇒ Object
set the value of a particular ID.
-
#audience_range(type) ⇒ Object
retrieve the value of a particular audience range.
-
#audience_range_set(type, min = nil, max = nil) ⇒ Object
set the value of a particular audience_range.
-
#dewey ⇒ Object
retrieve the dewey for this title.
-
#dewey=(code) ⇒ Object
add a dewey to the product.
-
#languages ⇒ Object
retrieve an array of all languages.
-
#replacement ⇒ Object
find the related_product that has relation_code 5.
-
#replacement=(value) ⇒ Object
set the proprietary_id of the replacement product.
-
#series(str) ⇒ Object
retrieve the value of a particular ID.
-
#series=(value) ⇒ Object
set the value of a particular ID.
-
#set(str) ⇒ Object
retrieve the value of a particular ID.
-
#set=(value) ⇒ Object
set the value of a particular ID.
-
#us_grade_range ⇒ Object
audience_range_qualifier: 11 = US school grades audience_range_precision: 1 = exact, 3 = from, 4 = to.
-
#us_grade_range=(range = []) ⇒ Object
set a new “audience of text” (role=1) country code for this particular product.
-
#work_identifier(str) ⇒ Object
retrieve the work_identifier that matches the given value.
Methods inherited from APAProduct
#add_bic_subject, #add_bisac_subject, #add_contributor, #agent_name, #agent_name=, #bic_subjects, #bisac_subjects, #contributors, #cover_url, #cover_url=, #cover_url_hq, #cover_url_hq=, #ean, #ean=, #height, #height=, #imprint, #imprint=, #isbn10, #isbn10=, #isbn13, #isbn13=, #long_description, #long_description=, #main_description, #main_description=, #market_country, #market_country=, #market_publishing_status, #market_publishing_status=, #measurement_system, #measurement_system=, #on_hand, #on_hand=, #on_order, #on_order=, #pack_quantity, #pack_quantity=, #price, #product_availability, #product_availability=, #proprietary_id, #proprietary_id=, #publisher, #publisher=, #publisher_website, #publisher_website=, #rrp_exc_sales_tax, #rrp_exc_sales_tax=, #rrp_inc_sales_tax, #rrp_inc_sales_tax=, #sales_restriction_type, #sales_restriction_type=, #short_description, #short_description=, #subtitle, #subtitle=, #supplier_email, #supplier_email=, #supplier_fax, #supplier_fax=, #supplier_name, #supplier_name=, #supplier_phone, #supplier_phone=, #supplier_website, #supplier_website=, #supply_country, #supply_country=, #thickness, #thickness=, #thumbnail_url, #thumbnail_url=, #title, #title=, #weight, #weight=, #width, #width=
Methods inherited from SimpleProduct
from_xml, #initialize, parse, parse_file, #product, #to_xml
Constructor Details
This class inherits a constructor from ONIX::SimpleProduct
Instance Method Details
#add_language(str, role = "1", country = "US") ⇒ Object
set a new language to this product str should be the languages name code (US)
113 114 115 116 117 118 119 |
# File 'lib/onix/sl_product.rb', line 113 def add_language(str, role = "1", country = "US") language = ::ONIX::Language.new language.language_role = role language.language_code = str language.country_code = country product.languages << language end |
#add_price(amount, *args) ⇒ Object
92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/onix/sl_product.rb', line 92 def add_price(amount, *args) = args..symbolize_keys # restrict keys to setter methods of format "text=" keys = ONIX::Price.instance_methods.delete_if{|x| ! /\w+=$/.match(x)}.map{|x| x.gsub(/=$/, '').to_sym} .assert_valid_keys(keys) # if price_type_code is not set, default to 1 .replace({:price_type_code => 1}.merge()) price = ONIX::Price.new price.price_amount = amount .each { |k, v| price.send("#{k}=", v) } supply = find_or_create_supply_detail supply.prices << price end |
#add_work_identifier(value, type = 1) ⇒ Object
set the value of a particular ID
63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/onix/sl_product.rb', line 63 def add_work_identifier(value, type = 1) # process based on value type if value.is_a?(WorkIdentifier) str = value.id_value obj = value else str = value obj = ONIX::WorkIdentifier.new(:work_id_type => type, :id_value => value) end # check if exists already unless work_identifier(str) product.work_identifiers << obj end end |
#audience_range(type) ⇒ Object
retrieve the value of a particular audience range
143 144 145 |
# File 'lib/onix/sl_product.rb', line 143 def audience_range(type) product.audience_ranges.find { |a| a.audience_range_qualifier == type } end |
#audience_range_set(type, min = nil, max = nil) ⇒ Object
set the value of a particular audience_range
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
# File 'lib/onix/sl_product.rb', line 148 def audience_range_set(type, min=nil, max=nil) a = audience_range(type) # create a new audience_range record if we need to if a.nil? a = ONIX::AudienceRange.new a.audience_range_qualifier = type product.audience_ranges << a end unless min.nil? a.audience_range_precisions << "03" a.audience_range_values << min end unless max.nil? a.audience_range_precisions << "04" a.audience_range_values << max end a.audience_range_precisions = ["01"] if min.nil? || max.nil? end |
#dewey ⇒ Object
retrieve the dewey for this title
122 123 124 |
# File 'lib/onix/sl_product.rb', line 122 def dewey product.subjects.find { |sub| sub.subject_scheme_id.to_i == 1 } # dewey = 1, abridged dewey = 2 end |
#dewey=(code) ⇒ Object
add a dewey to the product
127 128 129 |
# File 'lib/onix/sl_product.rb', line 127 def dewey=(code) add_subject code, "1" # dewey = 1, abridged dewey = 2 end |
#languages ⇒ Object
retrieve an array of all languages
107 108 109 |
# File 'lib/onix/sl_product.rb', line 107 def languages product.languages.collect { |language| language.language_code} end |
#replacement ⇒ Object
find the related_product that has relation_code 5
79 80 81 |
# File 'lib/onix/sl_product.rb', line 79 def replacement product..find { |obj| obj.relation_code == 5 } end |
#replacement=(value) ⇒ Object
set the proprietary_id of the replacement product
84 85 86 87 88 89 90 |
# File 'lib/onix/sl_product.rb', line 84 def replacement=(value) if obj = replacement obj.proprietary_id = value else product. << ONIX::RelatedProduct.new(:relation_code => 5, :proprietary_id => value) end end |
#series(str) ⇒ Object
retrieve the value of a particular ID
14 15 16 |
# File 'lib/onix/sl_product.rb', line 14 def series(str) product.series.find { |id| id.title_of_series == str } end |
#series=(value) ⇒ Object
set the value of a particular ID
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/onix/sl_product.rb', line 19 def series=(value) # process based on value type if value.is_a?(Series) str = value.title_of_series series_id = value else str = value series_id = ONIX::Series.new series_id.title_of_series = value end # check if exists already unless series(str) product.series << series_id end end |
#set(str) ⇒ Object
retrieve the value of a particular ID
36 37 38 |
# File 'lib/onix/sl_product.rb', line 36 def set(str) product.sets.find { |id| id.title_of_set == str } end |
#set=(value) ⇒ Object
set the value of a particular ID
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/onix/sl_product.rb', line 41 def set=(value) # process based on value type if value.is_a?(Set) str = value.title_of_set set_id = value else str = value set_id = ONIX::Set.new set_id.title_of_set = value end # check if exists already unless set(str) product.sets << set_id end end |
#us_grade_range ⇒ Object
audience_range_qualifier: 11 = US school grades audience_range_precision: 1 = exact, 3 = from, 4 = to
133 134 135 |
# File 'lib/onix/sl_product.rb', line 133 def us_grade_range audience_range(11) end |
#us_grade_range=(range = []) ⇒ Object
set a new “audience of text” (role=1) country code for this particular product
138 139 140 |
# File 'lib/onix/sl_product.rb', line 138 def us_grade_range=(range=[]) audience_range_set(11, range[0], range[1]) end |
#work_identifier(str) ⇒ Object
retrieve the work_identifier that matches the given value
58 59 60 |
# File 'lib/onix/sl_product.rb', line 58 def work_identifier(str) product.work_identifiers.find { |obj| obj.id_value == str } end |