milkfarm-onix 0.7.7
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +136 -0
- data/README.markdown +40 -0
- data/TODO +14 -0
- data/dtd/2.1r3/iso-amsa.ent +173 -0
- data/dtd/2.1r3/iso-amsb.ent +146 -0
- data/dtd/2.1r3/iso-amsc.ent +49 -0
- data/dtd/2.1r3/iso-amsn.ent +117 -0
- data/dtd/2.1r3/iso-amso.ent +77 -0
- data/dtd/2.1r3/iso-amsr.ent +205 -0
- data/dtd/2.1r3/iso-box.ent +67 -0
- data/dtd/2.1r3/iso-cyr1.ent +94 -0
- data/dtd/2.1r3/iso-cyr2.ent +53 -0
- data/dtd/2.1r3/iso-dia.ent +41 -0
- data/dtd/2.1r3/iso-grk3.ent +70 -0
- data/dtd/2.1r3/iso-lat1.ent +89 -0
- data/dtd/2.1r3/iso-lat2.ent +148 -0
- data/dtd/2.1r3/iso-mfrk.ent +79 -0
- data/dtd/2.1r3/iso-mopf.ent +53 -0
- data/dtd/2.1r3/iso-mscr.ent +79 -0
- data/dtd/2.1r3/iso-num.ent +103 -0
- data/dtd/2.1r3/iso-num.old.ent +103 -0
- data/dtd/2.1r3/iso-pub.ent +110 -0
- data/dtd/2.1r3/iso-tech.ent +183 -0
- data/dtd/2.1r3/onix-international.dtd +1012 -0
- data/dtd/2.1r3/onix-xhtml.elt +672 -0
- data/dtd/2.1r3/reference.elt +4758 -0
- data/dtd/2.1r3/xhtml-special.ent +79 -0
- data/dtd/2.1r3/xhtml-symbol.ent +242 -0
- data/lib/onix/addressee_identifier.rb +12 -0
- data/lib/onix/apa_product.rb +731 -0
- data/lib/onix/audience_range.rb +26 -0
- data/lib/onix/common.rb +26 -0
- data/lib/onix/contributor.rb +27 -0
- data/lib/onix/header.rb +46 -0
- data/lib/onix/imprint.rb +15 -0
- data/lib/onix/language.rb +14 -0
- data/lib/onix/lists/audience_code.rb +17 -0
- data/lib/onix/lists/country_code.rb +257 -0
- data/lib/onix/lists/language_code.rb +498 -0
- data/lib/onix/lists/language_role.rb +18 -0
- data/lib/onix/lists/notification_type.rb +19 -0
- data/lib/onix/lists/product_availability.rb +32 -0
- data/lib/onix/lists/product_form.rb +99 -0
- data/lib/onix/lists/product_form_detail.rb +157 -0
- data/lib/onix/market_representation.rb +19 -0
- data/lib/onix/measure.rb +14 -0
- data/lib/onix/media_file.rb +16 -0
- data/lib/onix/normaliser.rb +187 -0
- data/lib/onix/other_text.rb +17 -0
- data/lib/onix/price.rb +21 -0
- data/lib/onix/product.rb +73 -0
- data/lib/onix/product_identifier.rb +13 -0
- data/lib/onix/publisher.rb +16 -0
- data/lib/onix/reader.rb +187 -0
- data/lib/onix/sales_restriction.rb +12 -0
- data/lib/onix/sender_identifier.rb +14 -0
- data/lib/onix/series.rb +57 -0
- data/lib/onix/series_identifier.rb +13 -0
- data/lib/onix/simple_product.rb +47 -0
- data/lib/onix/sl_product.rb +131 -0
- data/lib/onix/stock.rb +15 -0
- data/lib/onix/subject.rb +16 -0
- data/lib/onix/supply_detail.rb +32 -0
- data/lib/onix/title.rb +17 -0
- data/lib/onix/website.rb +14 -0
- data/lib/onix/writer.rb +86 -0
- data/lib/onix.rb +114 -0
- data/spec/apa_product_spec.rb +59 -0
- data/spec/audience_range_spec.rb +46 -0
- data/spec/contributor_spec.rb +42 -0
- data/spec/header_spec.rb +123 -0
- data/spec/imprint_spec.rb +39 -0
- data/spec/language_spec.rb +42 -0
- data/spec/market_representation_spec.rb +41 -0
- data/spec/measure_spec.rb +43 -0
- data/spec/media_file_spec.rb +42 -0
- data/spec/normaliser_spec.rb +125 -0
- data/spec/other_text_spec.rb +40 -0
- data/spec/price_spec.rb +40 -0
- data/spec/product_identifier_spec.rb +40 -0
- data/spec/product_spec.rb +96 -0
- data/spec/publisher_spec.rb +38 -0
- data/spec/reader_spec.rb +131 -0
- data/spec/sales_restriction_spec.rb +35 -0
- data/spec/sender_identifier.rb +40 -0
- data/spec/series_identifier_spec.rb +38 -0
- data/spec/series_spec.rb +34 -0
- data/spec/sl_product_spec.rb +48 -0
- data/spec/stock_spec.rb +44 -0
- data/spec/subject_spec.rb +40 -0
- data/spec/supply_detail_spec.rb +53 -0
- data/spec/title_spec.rb +43 -0
- data/spec/website_spec.rb +41 -0
- data/spec/writer_spec.rb +81 -0
- data/support/entities.txt +1499 -0
- data/support/extract.rb +25 -0
- data/support/switch-onix-2.1-short-to-reference.xsl +23 -0
- data/support/switch-onix-tagnames-1.1.xsl +25 -0
- data/support/switch-onix-tagnames-2.0.xsl +37 -0
- metadata +209 -0
@@ -0,0 +1,731 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
module ONIX
|
4
|
+
class APAProduct < SimpleProduct
|
5
|
+
|
6
|
+
delegate :record_reference, :record_reference=
|
7
|
+
delegate :notification_type, :notification_type=
|
8
|
+
delegate :product_form, :product_form=
|
9
|
+
delegate :series, :series=
|
10
|
+
delegate :edition, :edition=
|
11
|
+
delegate :number_of_pages, :number_of_pages=
|
12
|
+
delegate :bic_main_subject, :bic_main_subject=
|
13
|
+
delegate :publishing_status, :publishing_status=
|
14
|
+
delegate :publication_date, :publication_date=
|
15
|
+
|
16
|
+
def measurement_system
|
17
|
+
@measurement_system ||= :metric
|
18
|
+
end
|
19
|
+
|
20
|
+
def measurement_system=(value)
|
21
|
+
if value == :metric || value == :imperial
|
22
|
+
@measurement_system = value
|
23
|
+
else
|
24
|
+
raise ArgumentError, "#{value} is not a recognised measurement system"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
# retrieve the current EAN
|
29
|
+
def ean
|
30
|
+
identifier(3).andand.id_value
|
31
|
+
end
|
32
|
+
|
33
|
+
# set a new EAN
|
34
|
+
def ean=(isbn)
|
35
|
+
identifier_set(3, isbn)
|
36
|
+
end
|
37
|
+
|
38
|
+
# retrieve the proprietary ID
|
39
|
+
def proprietary_id
|
40
|
+
identifier(1).andand.id_value
|
41
|
+
end
|
42
|
+
|
43
|
+
# set a new proprietary ID
|
44
|
+
def proprietary_id=(isbn)
|
45
|
+
identifier_set(1, isbn)
|
46
|
+
end
|
47
|
+
|
48
|
+
# retrieve the current ISBN 10
|
49
|
+
def isbn10
|
50
|
+
identifier(2).andand.id_value
|
51
|
+
end
|
52
|
+
|
53
|
+
# set a new ISBN 10
|
54
|
+
def isbn10=(isbn)
|
55
|
+
identifier_set(2, isbn)
|
56
|
+
end
|
57
|
+
|
58
|
+
# retrieve the current ISBN 13
|
59
|
+
def isbn13
|
60
|
+
identifier(15).andand.id_value
|
61
|
+
end
|
62
|
+
|
63
|
+
# set a new ISBN 13
|
64
|
+
def isbn13=(isbn)
|
65
|
+
identifier_set(15, isbn)
|
66
|
+
end
|
67
|
+
|
68
|
+
# retrieve the current title
|
69
|
+
def title
|
70
|
+
composite = product.titles.first
|
71
|
+
if composite.nil?
|
72
|
+
nil
|
73
|
+
else
|
74
|
+
composite.title_text || composite.title_without_prefix
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
# set a new title
|
79
|
+
def title=(str)
|
80
|
+
composite = product.titles.first
|
81
|
+
if composite.nil?
|
82
|
+
composite = ONIX::Title.new
|
83
|
+
composite.title_type = 1
|
84
|
+
product.titles << composite
|
85
|
+
end
|
86
|
+
composite.title_text = str
|
87
|
+
end
|
88
|
+
|
89
|
+
# retrieve the current subtitle
|
90
|
+
def subtitle
|
91
|
+
composite = product.titles.first
|
92
|
+
if composite.nil?
|
93
|
+
nil
|
94
|
+
else
|
95
|
+
composite.subtitle
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
# set a new subtitle
|
100
|
+
def subtitle=(str)
|
101
|
+
composite = product.titles.first
|
102
|
+
if composite.nil?
|
103
|
+
composite = ONIX::Title.new
|
104
|
+
composite.title_type = 1
|
105
|
+
product.titles << composite
|
106
|
+
end
|
107
|
+
composite.subtitle = str
|
108
|
+
end
|
109
|
+
|
110
|
+
# retrieve the current publisher website for this particular product
|
111
|
+
def publisher_website
|
112
|
+
website(2).andand.website_link
|
113
|
+
end
|
114
|
+
|
115
|
+
# set a new publisher website for this particular product
|
116
|
+
def publisher_website=(str)
|
117
|
+
website_set(2, str)
|
118
|
+
end
|
119
|
+
|
120
|
+
# retrieve the current supplier website for this particular product
|
121
|
+
def supplier_website
|
122
|
+
website(12).andand.website_link
|
123
|
+
end
|
124
|
+
|
125
|
+
# set a new supplier website for this particular product
|
126
|
+
def supplier_website=(str)
|
127
|
+
website_set(12, str)
|
128
|
+
end
|
129
|
+
|
130
|
+
# retrieve an array of all contributors
|
131
|
+
def contributors
|
132
|
+
product.contributors.collect { |contrib| contrib.person_name_inverted || contrib.person_name}
|
133
|
+
end
|
134
|
+
|
135
|
+
# set a new contributor to this product
|
136
|
+
# str should be the contributors name inverted (Healy, James)
|
137
|
+
def add_contributor(str, role = "A01")
|
138
|
+
contrib = ::ONIX::Contributor.new
|
139
|
+
contrib.sequence_number = product.contributors.size + 1
|
140
|
+
contrib.contributor_role = role
|
141
|
+
contrib.person_name_inverted = str
|
142
|
+
product.contributors << contrib
|
143
|
+
end
|
144
|
+
|
145
|
+
# return an array of BIC subjects for this title
|
146
|
+
# could be version 1 or version 2, most ONIX files don't
|
147
|
+
# specifiy
|
148
|
+
def bic_subjects
|
149
|
+
subjects = product.subjects.select { |sub| sub.subject_scheme_id.to_i == 12 }
|
150
|
+
subjects.collect { |sub| sub.subject_code}
|
151
|
+
end
|
152
|
+
|
153
|
+
# add a BIC subject code to the product
|
154
|
+
def add_bic_subject(code)
|
155
|
+
add_subject code, "12"
|
156
|
+
end
|
157
|
+
|
158
|
+
# return an array of BISAC subjects for this title
|
159
|
+
def bisac_subjects
|
160
|
+
subjects = product.subjects.select { |sub| sub.subject_scheme_id.to_i == 10 }
|
161
|
+
subjects.collect { |sub| sub.subject_code}
|
162
|
+
end
|
163
|
+
|
164
|
+
# add a BISAC subject code to the product
|
165
|
+
def add_bisac_subject(code)
|
166
|
+
add_subject code, "10"
|
167
|
+
end
|
168
|
+
|
169
|
+
# retrieve the url to the product cover image
|
170
|
+
def cover_url
|
171
|
+
media_file(4).andand.media_file_link
|
172
|
+
end
|
173
|
+
|
174
|
+
# set the url to the product cover image
|
175
|
+
def cover_url=(url)
|
176
|
+
# 4 - cover image
|
177
|
+
# 1 - URI
|
178
|
+
media_file_set(4,1,url)
|
179
|
+
end
|
180
|
+
|
181
|
+
# retrieve the url to the high quality product cover image
|
182
|
+
def cover_url_hq
|
183
|
+
media_file(6).andand.media_file_link
|
184
|
+
end
|
185
|
+
|
186
|
+
# set the url to the high quality product cover image
|
187
|
+
def cover_url_hq=(url)
|
188
|
+
# 6 - hq cover image
|
189
|
+
# 1 - URI
|
190
|
+
media_file_set(6,1,url)
|
191
|
+
end
|
192
|
+
|
193
|
+
# retrieve the url to the product thumbnail
|
194
|
+
def thumbnail_url
|
195
|
+
media_file(7).andand.media_file_link
|
196
|
+
end
|
197
|
+
|
198
|
+
# set the url to the product cover image
|
199
|
+
def thumbnail_url=(url)
|
200
|
+
# 7 - thumbnail image
|
201
|
+
# 1 - URI
|
202
|
+
media_file_set(7,1,url)
|
203
|
+
end
|
204
|
+
|
205
|
+
# retrieve the main description
|
206
|
+
def main_description
|
207
|
+
other_text(1).andand.text
|
208
|
+
end
|
209
|
+
|
210
|
+
# set the main description
|
211
|
+
def main_description=(t)
|
212
|
+
other_text_set(1,t)
|
213
|
+
end
|
214
|
+
|
215
|
+
# retrieve the short description
|
216
|
+
def short_description
|
217
|
+
other_text(2).andand.text
|
218
|
+
end
|
219
|
+
|
220
|
+
# set the short description
|
221
|
+
def short_description=(t)
|
222
|
+
other_text_set(2,t)
|
223
|
+
end
|
224
|
+
|
225
|
+
# retrieve the long description
|
226
|
+
def long_description
|
227
|
+
other_text(3).andand.text
|
228
|
+
end
|
229
|
+
|
230
|
+
# set the long description
|
231
|
+
def long_description=(t)
|
232
|
+
other_text_set(3,t)
|
233
|
+
end
|
234
|
+
|
235
|
+
# retrieve the imprint
|
236
|
+
def imprint
|
237
|
+
composite = product.imprints.first
|
238
|
+
composite ? composite.imprint_name : nil
|
239
|
+
end
|
240
|
+
|
241
|
+
# set a new imprint
|
242
|
+
def imprint=(str)
|
243
|
+
composite = product.imprints.first
|
244
|
+
if composite.nil?
|
245
|
+
composite = ONIX::Imprint.new
|
246
|
+
product.imprints << composite
|
247
|
+
end
|
248
|
+
composite.imprint_name = str
|
249
|
+
end
|
250
|
+
|
251
|
+
# retrieve the publisher
|
252
|
+
def publisher
|
253
|
+
publisher_get(1).andand.publisher_name
|
254
|
+
end
|
255
|
+
|
256
|
+
# set a new publisher
|
257
|
+
def publisher=(str)
|
258
|
+
publisher_set(1, str)
|
259
|
+
end
|
260
|
+
|
261
|
+
# retrieve the sales restriction type
|
262
|
+
def sales_restriction_type
|
263
|
+
composite = product.sales_restrictions.first
|
264
|
+
composite.nil? ? nil : composite.imprint_name
|
265
|
+
end
|
266
|
+
|
267
|
+
# set a new sales restriction type
|
268
|
+
def sales_restriction_type=(type)
|
269
|
+
composite = product.sales_restrictions.first
|
270
|
+
if composite.nil?
|
271
|
+
composite = ONIX::SalesRestriction.new
|
272
|
+
product.sales_restrictions << composite
|
273
|
+
end
|
274
|
+
composite.sales_restriction_type = type
|
275
|
+
end
|
276
|
+
|
277
|
+
# retrieve the supplier name
|
278
|
+
def supplier_name
|
279
|
+
composite = product.supply_details.first
|
280
|
+
composite.nil? ? nil : composite.supplier_name
|
281
|
+
end
|
282
|
+
|
283
|
+
# set a new supplier name
|
284
|
+
def supplier_name=(str)
|
285
|
+
composite = find_or_create_supply_detail
|
286
|
+
composite.supplier_name = str
|
287
|
+
end
|
288
|
+
|
289
|
+
# retrieve the supplier phone number
|
290
|
+
def supplier_phone
|
291
|
+
composite = product.supply_details.first
|
292
|
+
composite.nil? ? nil : composite.telephone_number
|
293
|
+
end
|
294
|
+
|
295
|
+
# set a new supplier phone number
|
296
|
+
def supplier_phone=(str)
|
297
|
+
composite = find_or_create_supply_detail
|
298
|
+
composite.telephone_number = str
|
299
|
+
end
|
300
|
+
|
301
|
+
# retrieve the supplier fax number
|
302
|
+
def supplier_fax
|
303
|
+
composite = product.supply_details.first
|
304
|
+
composite.nil? ? nil : composite.fax_number
|
305
|
+
end
|
306
|
+
|
307
|
+
# set a new supplier fax number
|
308
|
+
def supplier_fax=(str)
|
309
|
+
composite = find_or_create_supply_detail
|
310
|
+
composite.fax_number = str
|
311
|
+
end
|
312
|
+
|
313
|
+
# retrieve the supplier email address
|
314
|
+
def supplier_email
|
315
|
+
composite = product.supply_details.first
|
316
|
+
composite.nil? ? nil : composite.email_address
|
317
|
+
end
|
318
|
+
|
319
|
+
# set a new supplier email address
|
320
|
+
def supplier_email=(str)
|
321
|
+
composite = find_or_create_supply_detail
|
322
|
+
composite.email_address = str
|
323
|
+
end
|
324
|
+
|
325
|
+
# retrieve the supply country code
|
326
|
+
def supply_country
|
327
|
+
composite = product.supply_details.first
|
328
|
+
composite.nil? ? nil : composite.supply_to_country
|
329
|
+
end
|
330
|
+
|
331
|
+
# set a new supply country code
|
332
|
+
def supply_country=(str)
|
333
|
+
composite = find_or_create_supply_detail
|
334
|
+
composite.supply_to_country = str
|
335
|
+
end
|
336
|
+
|
337
|
+
# retrieve the product availability code
|
338
|
+
def product_availability
|
339
|
+
composite = product.supply_details.first
|
340
|
+
composite.nil? ? nil : composite.product_availability
|
341
|
+
end
|
342
|
+
|
343
|
+
# set a new product availability
|
344
|
+
def product_availability=(num)
|
345
|
+
composite = find_or_create_supply_detail
|
346
|
+
composite.product_availability = num
|
347
|
+
end
|
348
|
+
|
349
|
+
# retrieve the number in stock
|
350
|
+
def on_hand
|
351
|
+
supply = find_or_create_supply_detail
|
352
|
+
composite = supply.stock.first
|
353
|
+
if composite.nil?
|
354
|
+
composite = ONIX::Stock.new
|
355
|
+
supply.stock << composite
|
356
|
+
end
|
357
|
+
composite.on_hand
|
358
|
+
end
|
359
|
+
|
360
|
+
# set a new in stock quantity
|
361
|
+
def on_hand=(num)
|
362
|
+
supply = find_or_create_supply_detail
|
363
|
+
composite = supply.stock.first
|
364
|
+
if composite.nil?
|
365
|
+
composite = ONIX::Stock.new
|
366
|
+
supply.stock << composite
|
367
|
+
end
|
368
|
+
composite.on_hand = num
|
369
|
+
end
|
370
|
+
|
371
|
+
# retrieve the number on order
|
372
|
+
def on_order
|
373
|
+
supply = find_or_create_supply_detail
|
374
|
+
composite = supply.stock.first
|
375
|
+
if composite.nil?
|
376
|
+
composite = ONIX::Stock.new
|
377
|
+
supply.stock << composite
|
378
|
+
end
|
379
|
+
composite.on_order
|
380
|
+
end
|
381
|
+
|
382
|
+
# set a new on order quantity
|
383
|
+
def on_order=(num)
|
384
|
+
supply = find_or_create_supply_detail
|
385
|
+
composite = supply.stock.first
|
386
|
+
if composite.nil?
|
387
|
+
composite = ONIX::Stock.new
|
388
|
+
supply.stock << composite
|
389
|
+
end
|
390
|
+
composite.on_order = num
|
391
|
+
end
|
392
|
+
|
393
|
+
# retrieve the supplier phone number
|
394
|
+
def pack_quantity
|
395
|
+
composite = product.supply_details.first
|
396
|
+
composite.nil? ? nil : composite.pack_quantity
|
397
|
+
end
|
398
|
+
|
399
|
+
# set a new supplier phone number
|
400
|
+
def pack_quantity=(val)
|
401
|
+
composite = find_or_create_supply_detail
|
402
|
+
composite.pack_quantity = val.to_i
|
403
|
+
end
|
404
|
+
|
405
|
+
# retrieve the rrp excluding any sales tax
|
406
|
+
def rrp_exc_sales_tax
|
407
|
+
price_get(1).andand.price_amount
|
408
|
+
end
|
409
|
+
|
410
|
+
# set the rrp excluding any sales tax
|
411
|
+
def rrp_exc_sales_tax=(num)
|
412
|
+
price_set(1, num)
|
413
|
+
end
|
414
|
+
|
415
|
+
# retrieve the rrp including any sales tax
|
416
|
+
def rrp_inc_sales_tax
|
417
|
+
price_get(2).andand.price_amount
|
418
|
+
end
|
419
|
+
|
420
|
+
# set the rrp including any sales tax
|
421
|
+
def rrp_inc_sales_tax=(num)
|
422
|
+
price_set(2, num)
|
423
|
+
end
|
424
|
+
|
425
|
+
# just get the first price we can find, regardless of the type.
|
426
|
+
# useful as a backup for reading files from that don't contain a type
|
427
|
+
def price
|
428
|
+
price_get(nil).andand.price_amount
|
429
|
+
end
|
430
|
+
|
431
|
+
# retrieve the height of the product
|
432
|
+
#
|
433
|
+
# If APAProduct#measurement_system is metric, these will be in mm, otherwise they
|
434
|
+
# will be in inches.
|
435
|
+
#
|
436
|
+
def height
|
437
|
+
# TODO: auto unit conversion
|
438
|
+
measurement(1).andand.measurement
|
439
|
+
end
|
440
|
+
|
441
|
+
# set the height of the book
|
442
|
+
#
|
443
|
+
# If APAProduct#measurement_system is metric, this should be in mm, otherwise it
|
444
|
+
# will be in inches.
|
445
|
+
#
|
446
|
+
def height=(value)
|
447
|
+
if measurement_system == :metric
|
448
|
+
measurement_set(1,value, "mm")
|
449
|
+
elsif measurement_system == :imperial
|
450
|
+
measurement_set(1,value, "in")
|
451
|
+
end
|
452
|
+
end
|
453
|
+
|
454
|
+
# retrieve the width of the product
|
455
|
+
#
|
456
|
+
# If APAProduct#measurement_system is metric, these will be in mm, otherwise they
|
457
|
+
# will be in inches.
|
458
|
+
#
|
459
|
+
def width
|
460
|
+
# TODO: auto unit conversion
|
461
|
+
measurement(2).andand.measurement
|
462
|
+
end
|
463
|
+
|
464
|
+
# set the width of the product
|
465
|
+
#
|
466
|
+
# If APAProduct#measurement_system is metric, this should be in mm, otherwise it
|
467
|
+
# will be in inches.
|
468
|
+
#
|
469
|
+
def width=(value)
|
470
|
+
if measurement_system == :metric
|
471
|
+
measurement_set(2,value, "mm")
|
472
|
+
elsif measurement_system == :imperial
|
473
|
+
measurement_set(2,value, "in")
|
474
|
+
end
|
475
|
+
end
|
476
|
+
|
477
|
+
# retrieve the weight of the product
|
478
|
+
#
|
479
|
+
# If APAProduct#measurement_system is metric, these will be in grams, otherwise they
|
480
|
+
# will be in ounces.
|
481
|
+
#
|
482
|
+
def weight
|
483
|
+
# TODO: auto unit conversion
|
484
|
+
measurement(8).andand.measurement
|
485
|
+
end
|
486
|
+
|
487
|
+
# set the weight of the product
|
488
|
+
#
|
489
|
+
# If APAProduct#measurement_system is metric, this should be in grams, otherwise it
|
490
|
+
# will be in ounces.
|
491
|
+
#
|
492
|
+
def weight=(value)
|
493
|
+
if measurement_system == :metric
|
494
|
+
measurement_set(8,value, "gr")
|
495
|
+
elsif measurement_system == :imperial
|
496
|
+
measurement_set(8,value, "oz")
|
497
|
+
end
|
498
|
+
end
|
499
|
+
|
500
|
+
# retrieve the thickness of the product
|
501
|
+
#
|
502
|
+
# If APAProduct#measurement_system is metric, these will be in mm, otherwise they
|
503
|
+
# will be in inches.
|
504
|
+
#
|
505
|
+
def thickness
|
506
|
+
# TODO: auto unit conversion
|
507
|
+
measurement(3).andand.measurement
|
508
|
+
end
|
509
|
+
|
510
|
+
# set the thickness of the product
|
511
|
+
#
|
512
|
+
# If APAProduct#measurement_system is metric, this should be in mm, otherwise it
|
513
|
+
# will be in inches.
|
514
|
+
#
|
515
|
+
def thickness=(value)
|
516
|
+
if measurement_system == :metric
|
517
|
+
measurement_set(3,value, "mm")
|
518
|
+
elsif measurement_system == :imperial
|
519
|
+
measurement_set(3,value, "in")
|
520
|
+
end
|
521
|
+
end
|
522
|
+
|
523
|
+
def agent_name
|
524
|
+
reps = product.market_representations.first
|
525
|
+
return nil if reps.nil?
|
526
|
+
reps.agent_name
|
527
|
+
end
|
528
|
+
|
529
|
+
def agent_name=(value)
|
530
|
+
reps = product.market_representations.first
|
531
|
+
if reps.nil?
|
532
|
+
reps = ONIX::MarketRepresentation.new
|
533
|
+
product.market_representations << reps
|
534
|
+
end
|
535
|
+
reps.agent_name = value.to_s
|
536
|
+
end
|
537
|
+
|
538
|
+
def market_country
|
539
|
+
reps = product.market_representations.first
|
540
|
+
return nil if reps.nil?
|
541
|
+
reps.market_country
|
542
|
+
end
|
543
|
+
|
544
|
+
def market_country=(value)
|
545
|
+
reps = product.market_representations.first
|
546
|
+
if reps.nil?
|
547
|
+
reps = ONIX::MarketRepresentation.new
|
548
|
+
product.market_representations << reps
|
549
|
+
end
|
550
|
+
reps.market_country = value.to_s
|
551
|
+
end
|
552
|
+
|
553
|
+
def market_publishing_status
|
554
|
+
reps = product.market_representations.first
|
555
|
+
return nil if reps.nil?
|
556
|
+
reps.market_publishing_status
|
557
|
+
end
|
558
|
+
|
559
|
+
def market_publishing_status=(value)
|
560
|
+
reps = product.market_representations.first
|
561
|
+
if reps.nil?
|
562
|
+
reps = ONIX::MarketRepresentation.new
|
563
|
+
product.market_representations << reps
|
564
|
+
end
|
565
|
+
reps.market_publishing_status = value.to_i
|
566
|
+
end
|
567
|
+
|
568
|
+
private
|
569
|
+
|
570
|
+
# add a new subject to this product
|
571
|
+
# str should be the subject code
|
572
|
+
# type should be the code for the subject scheme you're using. See ONIX codelist 27.
|
573
|
+
# 12 is BIC
|
574
|
+
def add_subject(str, type = "12")
|
575
|
+
subject = ::ONIX::Subject.new
|
576
|
+
subject.subject_scheme_id = type.to_i
|
577
|
+
subject.subject_code = str
|
578
|
+
product.subjects << subject
|
579
|
+
end
|
580
|
+
|
581
|
+
def find_or_create_supply_detail
|
582
|
+
composite = product.supply_details.first
|
583
|
+
if composite.nil?
|
584
|
+
composite = ONIX::SupplyDetail.new
|
585
|
+
product.supply_details << composite
|
586
|
+
end
|
587
|
+
composite
|
588
|
+
end
|
589
|
+
|
590
|
+
# retrieve the value of a particular ID
|
591
|
+
def identifier(type)
|
592
|
+
product.product_identifiers.find { |id| id.product_id_type == type }
|
593
|
+
end
|
594
|
+
|
595
|
+
# set the value of a particular ID
|
596
|
+
def identifier_set(type, value)
|
597
|
+
isbn_id = identifier(type)
|
598
|
+
|
599
|
+
# create a new isbn record if we need to
|
600
|
+
if isbn_id.nil?
|
601
|
+
isbn_id = ONIX::ProductIdentifier.new
|
602
|
+
isbn_id.product_id_type = type
|
603
|
+
product.product_identifiers << isbn_id
|
604
|
+
end
|
605
|
+
|
606
|
+
isbn_id.id_value = value
|
607
|
+
end
|
608
|
+
|
609
|
+
# retrieve the value of a particular measurement
|
610
|
+
def measurement(type)
|
611
|
+
product.measurements.find { |m| m.measure_type_code == type }
|
612
|
+
end
|
613
|
+
|
614
|
+
# set the value of a particular measurement
|
615
|
+
def measurement_set(type, value, unit)
|
616
|
+
measure = measurement(type)
|
617
|
+
|
618
|
+
# create a new isbn record if we need to
|
619
|
+
if measure.nil?
|
620
|
+
measure = ONIX::Measure.new
|
621
|
+
measure.measure_type_code = type
|
622
|
+
product.measurements << measure
|
623
|
+
end
|
624
|
+
|
625
|
+
# store the new value
|
626
|
+
measure.measurement = value
|
627
|
+
measure.measure_unit_code = unit.to_s
|
628
|
+
end
|
629
|
+
|
630
|
+
# retrieve the value of a particular media file
|
631
|
+
def media_file(type)
|
632
|
+
product.media_files.find { |m| m.media_file_type_code == type }
|
633
|
+
end
|
634
|
+
|
635
|
+
# set the value of a particular ID
|
636
|
+
def media_file_set(type, link_type, value)
|
637
|
+
media = media_file(type)
|
638
|
+
|
639
|
+
# create a new isbn record if we need to
|
640
|
+
if media.nil?
|
641
|
+
media = ONIX::MediaFile.new
|
642
|
+
media.media_file_type_code = type
|
643
|
+
media.media_file_link_type_code = link_type
|
644
|
+
product.media_files << media
|
645
|
+
end
|
646
|
+
|
647
|
+
# store the new value
|
648
|
+
media.media_file_link = value.to_s
|
649
|
+
end
|
650
|
+
|
651
|
+
# retrieve the value of a particular price
|
652
|
+
def price_get(type)
|
653
|
+
supply = find_or_create_supply_detail
|
654
|
+
supply.prices.find { |p| p.price_type_code == type }
|
655
|
+
end
|
656
|
+
|
657
|
+
# set the value of a particular price
|
658
|
+
def price_set(type, num)
|
659
|
+
p = price_get(type)
|
660
|
+
|
661
|
+
# create a new isbn record if we need to
|
662
|
+
if p.nil?
|
663
|
+
supply = find_or_create_supply_detail
|
664
|
+
p = ONIX::Price.new
|
665
|
+
p.price_type_code = type
|
666
|
+
supply.prices << p
|
667
|
+
end
|
668
|
+
|
669
|
+
# store the new value
|
670
|
+
p.price_amount = num
|
671
|
+
end
|
672
|
+
|
673
|
+
# retrieve the value of a particular publisher
|
674
|
+
def publisher_get(type)
|
675
|
+
product.publishers.find { |pub| pub.publishing_role == type }
|
676
|
+
end
|
677
|
+
|
678
|
+
# set the value of a particular ID
|
679
|
+
def publisher_set(type, value)
|
680
|
+
pub = publisher_get(type)
|
681
|
+
|
682
|
+
# create a new isbn record if we need to
|
683
|
+
if pub.nil?
|
684
|
+
pub = ONIX::Publisher.new
|
685
|
+
pub.publishing_role = type
|
686
|
+
product.publishers << pub
|
687
|
+
end
|
688
|
+
|
689
|
+
# store the new value
|
690
|
+
pub.publisher_name = value.to_s
|
691
|
+
end
|
692
|
+
|
693
|
+
# retrieve the value of a particular other text value
|
694
|
+
def other_text(type)
|
695
|
+
product.text.find { |t| t.text_type_code == type }
|
696
|
+
end
|
697
|
+
|
698
|
+
# set the value of a particular other text value
|
699
|
+
def other_text_set(type, value)
|
700
|
+
text = other_text(type)
|
701
|
+
|
702
|
+
if text.nil?
|
703
|
+
text = ONIX::OtherText.new
|
704
|
+
text.text_type_code = type
|
705
|
+
product.text << text
|
706
|
+
end
|
707
|
+
|
708
|
+
# store the new value
|
709
|
+
text.text = value.to_s
|
710
|
+
end
|
711
|
+
|
712
|
+
# retrieve the value of a particular website
|
713
|
+
def website(type)
|
714
|
+
product.websites.find { |site| site.website_role == type }
|
715
|
+
end
|
716
|
+
|
717
|
+
# set the value of a particular website
|
718
|
+
def website_set(type, value)
|
719
|
+
site = website(type)
|
720
|
+
|
721
|
+
# create a new website record if we need to
|
722
|
+
if site.nil?
|
723
|
+
site = ONIX::Website.new
|
724
|
+
site.website_role = type
|
725
|
+
product.websites << site
|
726
|
+
end
|
727
|
+
|
728
|
+
site.website_link = value.to_s
|
729
|
+
end
|
730
|
+
end
|
731
|
+
end
|