Class: ONIX::APAProduct

Inherits:
SimpleProduct show all
Defined in:
lib/onix/apa_product.rb

Instance Method Summary collapse

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_bic_subject(code) ⇒ Object

add a BIC subject code to the product



154
155
156
# File 'lib/onix/apa_product.rb', line 154

def add_bic_subject(code)
  add_subject code, "12"
end

#add_bisac_subject(code) ⇒ Object

add a BISAC subject code to the product



165
166
167
# File 'lib/onix/apa_product.rb', line 165

def add_bisac_subject(code)
  add_subject code, "10"
end

#add_contributor(str, role = "A01") ⇒ Object

set a new contributor to this product str should be the contributors name inverted (Healy, James)



137
138
139
140
141
142
143
# File 'lib/onix/apa_product.rb', line 137

def add_contributor(str, role = "A01")
  contrib = ::ONIX::Contributor.new
  contrib.sequence_number = product.contributors.size + 1
  contrib.contributor_role = role
  contrib.person_name_inverted = str
  product.contributors << contrib
end

#agent_nameObject



511
512
513
514
515
# File 'lib/onix/apa_product.rb', line 511

def agent_name
  reps = product.market_representations.first
  return nil if reps.nil?
  reps.agent_name
end

#agent_name=(value) ⇒ Object



517
518
519
520
521
522
523
524
# File 'lib/onix/apa_product.rb', line 517

def agent_name=(value)
  reps = product.market_representations.first
  if reps.nil?
    reps = ONIX::MarketRepresentation.new
    product.market_representations << reps
  end
  reps.agent_name = value.to_s
end

#bic_subjectsObject

return an array of BIC subjects for this title could be version 1 or version 2, most ONIX files don’t specifiy



148
149
150
151
# File 'lib/onix/apa_product.rb', line 148

def bic_subjects
  subjects = product.subjects.select { |sub| sub.subject_scheme_id.to_i == 12 }
  subjects.collect { |sub| sub.subject_code}
end

#bisac_subjectsObject

return an array of BISAC subjects for this title



159
160
161
162
# File 'lib/onix/apa_product.rb', line 159

def bisac_subjects
  subjects = product.subjects.select { |sub| sub.subject_scheme_id.to_i == 10 }
  subjects.collect { |sub| sub.subject_code}
end

#contributorsObject

retrieve an array of all contributors



131
132
133
# File 'lib/onix/apa_product.rb', line 131

def contributors
  product.contributors.collect { |contrib| contrib.person_name_inverted || contrib.person_name}
end

#cover_urlObject

retrieve the url to the product cover image



170
171
172
# File 'lib/onix/apa_product.rb', line 170

def cover_url
  media_file(4).andand.media_file_link
end

#cover_url=(url) ⇒ Object

set the url to the product cover image



175
176
177
178
179
# File 'lib/onix/apa_product.rb', line 175

def cover_url=(url)
  # 4 - cover image
  # 1 - URI
  media_file_set(4,1,url)
end

#cover_url_hqObject

retrieve the url to the high quality product cover image



182
183
184
# File 'lib/onix/apa_product.rb', line 182

def cover_url_hq
  media_file(6).andand.media_file_link
end

#cover_url_hq=(url) ⇒ Object

set the url to the high quality product cover image



187
188
189
190
191
# File 'lib/onix/apa_product.rb', line 187

def cover_url_hq=(url)
  # 6 - hq cover image
  # 1 - URI
  media_file_set(6,1,url)
end

#eanObject

retrieve the current EAN



29
30
31
# File 'lib/onix/apa_product.rb', line 29

def ean
  identifier(3).andand.id_value
end

#ean=(isbn) ⇒ Object

set a new EAN



34
35
36
# File 'lib/onix/apa_product.rb', line 34

def ean=(isbn)
  identifier_set(3, isbn)
end

#heightObject

retrieve the height of the product

If APAProduct#measurement_system is metric, these will be in mm, otherwise they will be in inches.



424
425
426
427
# File 'lib/onix/apa_product.rb', line 424

def height
  # TODO: auto unit conversion
  measurement(1).andand.measurement
end

#height=(value) ⇒ Object

set the height of the book

If APAProduct#measurement_system is metric, this should be in mm, otherwise it will be in inches.



434
435
436
437
438
439
440
# File 'lib/onix/apa_product.rb', line 434

def height=(value)
  if measurement_system == :metric
    measurement_set(1,value, "mm")
  elsif measurement_system == :imperial
    measurement_set(1,value, "in")
  end
end

#imprintObject

retrieve the imprint



236
237
238
239
# File 'lib/onix/apa_product.rb', line 236

def imprint
  composite = product.imprints.first
  composite ? composite.imprint_name : nil
end

#imprint=(str) ⇒ Object

set a new imprint



242
243
244
245
246
247
248
249
# File 'lib/onix/apa_product.rb', line 242

def imprint=(str)
  composite = product.imprints.first
  if composite.nil?
    composite =  ONIX::Imprint.new
    product.imprints << composite
  end
  composite.imprint_name = str
end

#isbn10Object

retrieve the current ISBN 10



49
50
51
# File 'lib/onix/apa_product.rb', line 49

def isbn10
  identifier(2).andand.id_value
end

#isbn10=(isbn) ⇒ Object

set a new ISBN 10



54
55
56
# File 'lib/onix/apa_product.rb', line 54

def isbn10=(isbn)
  identifier_set(2, isbn)
end

#isbn13Object

retrieve the current ISBN 13



59
60
61
# File 'lib/onix/apa_product.rb', line 59

def isbn13
  identifier(15).andand.id_value
end

#isbn13=(isbn) ⇒ Object

set a new ISBN 13



64
65
66
# File 'lib/onix/apa_product.rb', line 64

def isbn13=(isbn)
  identifier_set(15, isbn)
end

#long_descriptionObject

retrieve the long description



226
227
228
# File 'lib/onix/apa_product.rb', line 226

def long_description
  other_text(3).andand.text
end

#long_description=(t) ⇒ Object

set the long description



231
232
233
# File 'lib/onix/apa_product.rb', line 231

def long_description=(t)
  other_text_set(3,t)
end

#main_descriptionObject

retrieve the main description



206
207
208
# File 'lib/onix/apa_product.rb', line 206

def main_description
  other_text(1).andand.text
end

#main_description=(t) ⇒ Object

set the main description



211
212
213
# File 'lib/onix/apa_product.rb', line 211

def main_description=(t)
  other_text_set(1,t)
end

#market_countryObject



526
527
528
529
530
# File 'lib/onix/apa_product.rb', line 526

def market_country
  reps = product.market_representations.first
  return nil if reps.nil?
  reps.market_country
end

#market_country=(value) ⇒ Object



532
533
534
535
536
537
538
539
# File 'lib/onix/apa_product.rb', line 532

def market_country=(value)
  reps = product.market_representations.first
  if reps.nil?
    reps = ONIX::MarketRepresentation.new
    product.market_representations << reps
  end
  reps.market_country = value.to_s
end

#market_publishing_statusObject



541
542
543
544
545
# File 'lib/onix/apa_product.rb', line 541

def market_publishing_status
  reps = product.market_representations.first
  return nil if reps.nil?
  reps.market_publishing_status
end

#market_publishing_status=(value) ⇒ Object



547
548
549
550
551
552
553
554
# File 'lib/onix/apa_product.rb', line 547

def market_publishing_status=(value)
  reps = product.market_representations.first
  if reps.nil?
    reps = ONIX::MarketRepresentation.new
    product.market_representations << reps
  end
  reps.market_publishing_status = value.to_i
end

#measurement_systemObject



16
17
18
# File 'lib/onix/apa_product.rb', line 16

def measurement_system
  @measurement_system ||= :metric
end

#measurement_system=(value) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/onix/apa_product.rb', line 20

def measurement_system=(value)
  if value == :metric || value == :imperial
    @measurement_system = value
  else
    raise ArgumentError, "#{value} is not a recognised measurement system"
  end
end

#on_handObject

retrieve the number in stock



350
351
352
353
354
355
356
357
358
# File 'lib/onix/apa_product.rb', line 350

def on_hand
  supply = find_or_create_supply_detail
  composite = supply.stock.first
  if composite.nil?
    composite = ONIX::Stock.new
    supply.stock << composite
  end
  composite.on_hand
end

#on_hand=(num) ⇒ Object

set a new in stock quantity



361
362
363
364
365
366
367
368
369
# File 'lib/onix/apa_product.rb', line 361

def on_hand=(num)
  supply = find_or_create_supply_detail
  composite = supply.stock.first
  if composite.nil?
    composite = ONIX::Stock.new
    supply.stock << composite
  end
  composite.on_hand = num
end

#on_orderObject

retrieve the number on order



372
373
374
375
376
377
378
379
380
# File 'lib/onix/apa_product.rb', line 372

def on_order
  supply = find_or_create_supply_detail
  composite = supply.stock.first
  if composite.nil?
    composite = ONIX::Stock.new
    supply.stock << composite
  end
  composite.on_order
end

#on_order=(num) ⇒ Object

set a new on order quantity



383
384
385
386
387
388
389
390
391
# File 'lib/onix/apa_product.rb', line 383

def on_order=(num)
  supply = find_or_create_supply_detail
  composite = supply.stock.first
  if composite.nil?
    composite = ONIX::Stock.new
    supply.stock << composite
  end
  composite.on_order = num
end

#priceObject

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



415
416
417
# File 'lib/onix/apa_product.rb', line 415

def price
  price_get(nil).andand.price_amount
end

#product_availabilityObject

retrieve the product availability code



338
339
340
341
# File 'lib/onix/apa_product.rb', line 338

def product_availability
  composite = product.supplier_details.first
  composite.nil? ? nil : composite.product_availability
end

#product_availability=(num) ⇒ Object

set a new product availability



344
345
346
347
# File 'lib/onix/apa_product.rb', line 344

def product_availability=(num)
  composite = find_or_create_supply_detail
  composite.product_availability = num
end

#proprietary_idObject

retrieve the proprietary ID



39
40
41
# File 'lib/onix/apa_product.rb', line 39

def proprietary_id
  identifier(1).andand.id_value
end

#proprietary_id=(isbn) ⇒ Object

set a new proprietary ID



44
45
46
# File 'lib/onix/apa_product.rb', line 44

def proprietary_id=(isbn)
  identifier_set(1, isbn)
end

#publisherObject

retrieve the publisher



252
253
254
# File 'lib/onix/apa_product.rb', line 252

def publisher
  publisher_get(1).andand.publisher_name
end

#publisher=(str) ⇒ Object

set a new publisher



257
258
259
# File 'lib/onix/apa_product.rb', line 257

def publisher=(str)
  publisher_set(1, str)
end

#publisher_websiteObject

retrieve the current publisher website for this particular product



111
112
113
# File 'lib/onix/apa_product.rb', line 111

def publisher_website
  website(2).andand.website_link
end

#publisher_website=(str) ⇒ Object

set a new publisher website for this particular product



116
117
118
# File 'lib/onix/apa_product.rb', line 116

def publisher_website=(str)
  website_set(2, str)
end

#rrp_exc_sales_taxObject

retrieve the rrp excluding any sales tax



394
395
396
# File 'lib/onix/apa_product.rb', line 394

def rrp_exc_sales_tax
  price_get(1).andand.price_amount
end

#rrp_exc_sales_tax=(num) ⇒ Object

set the rrp excluding any sales tax



399
400
401
# File 'lib/onix/apa_product.rb', line 399

def rrp_exc_sales_tax=(num)
  price_set(1, num)
end

#rrp_inc_sales_taxObject

retrieve the rrp including any sales tax



404
405
406
# File 'lib/onix/apa_product.rb', line 404

def rrp_inc_sales_tax
  price_get(2).andand.price_amount
end

#rrp_inc_sales_tax=(num) ⇒ Object

set the rrp including any sales tax



409
410
411
# File 'lib/onix/apa_product.rb', line 409

def rrp_inc_sales_tax=(num)
  price_set(2, num)
end

#sales_restriction_typeObject

retrieve the sales restriction type



262
263
264
265
# File 'lib/onix/apa_product.rb', line 262

def sales_restriction_type
  composite = product.sales_restrictions.first
  composite.nil? ? nil : composite.imprint_name
end

#sales_restriction_type=(type) ⇒ Object

set a new sales restriction type



268
269
270
271
272
273
274
275
# File 'lib/onix/apa_product.rb', line 268

def sales_restriction_type=(type)
  composite = product.sales_restrictions.first
  if composite.nil?
    composite =  ONIX::SalesRestriction.new
    product.sales_restrictions << composite
  end
  composite.sales_restriction_type = type
end

#short_descriptionObject

retrieve the short description



216
217
218
# File 'lib/onix/apa_product.rb', line 216

def short_description
  other_text(2).andand.text
end

#short_description=(t) ⇒ Object

set the short description



221
222
223
# File 'lib/onix/apa_product.rb', line 221

def short_description=(t)
  other_text_set(2,t)
end

#subtitleObject

retrieve the current subtitle



90
91
92
93
94
95
96
97
# File 'lib/onix/apa_product.rb', line 90

def subtitle
  composite = product.titles.first
  if composite.nil?
    nil
  else
    composite.subtitle
  end
end

#subtitle=(str) ⇒ Object

set a new subtitle



100
101
102
103
104
105
106
107
108
# File 'lib/onix/apa_product.rb', line 100

def subtitle=(str)
  composite = product.titles.first
  if composite.nil?
    composite =  ONIX::Title.new
    composite.title_type = 1
    product.titles << composite
  end
  composite.subtitle = str
end

#supplier_emailObject

retrieve the supplier email address



314
315
316
317
# File 'lib/onix/apa_product.rb', line 314

def supplier_email
  composite = product.supplier_details.first
  composite.nil? ? nil : composite.email_address
end

#supplier_email=(str) ⇒ Object

set a new supplier email address



320
321
322
323
# File 'lib/onix/apa_product.rb', line 320

def supplier_email=(str)
  composite = find_or_create_supply_detail
  composite.email_address = str
end

#supplier_faxObject

retrieve the supplier fax number



302
303
304
305
# File 'lib/onix/apa_product.rb', line 302

def supplier_fax
  composite = product.supplier_details.first
  composite.nil? ? nil : composite.fax_number
end

#supplier_fax=(str) ⇒ Object

set a new supplier fax number



308
309
310
311
# File 'lib/onix/apa_product.rb', line 308

def supplier_fax=(str)
  composite = find_or_create_supply_detail
  composite.fax_number = str
end

#supplier_nameObject

retrieve the supplier name



278
279
280
281
# File 'lib/onix/apa_product.rb', line 278

def supplier_name
  composite = product.supplier_details.first
  composite.nil? ? nil : composite.supplier_name
end

#supplier_name=(str) ⇒ Object

set a new supplier name



284
285
286
287
# File 'lib/onix/apa_product.rb', line 284

def supplier_name=(str)
  composite = find_or_create_supply_detail
  composite.supplier_name = str
end

#supplier_phoneObject

retrieve the supplier phone number



290
291
292
293
# File 'lib/onix/apa_product.rb', line 290

def supplier_phone
  composite = product.supplier_details.first
  composite.nil? ? nil : composite.telephone_number
end

#supplier_phone=(str) ⇒ Object

set a new supplier phone number



296
297
298
299
# File 'lib/onix/apa_product.rb', line 296

def supplier_phone=(str)
  composite = find_or_create_supply_detail
  composite.telephone_number = str
end

#supplier_websiteObject

retrieve the current supplier website for this particular product



121
122
123
# File 'lib/onix/apa_product.rb', line 121

def supplier_website
  website(12).andand.website_link
end

#supplier_website=(str) ⇒ Object

set a new supplier website for this particular product



126
127
128
# File 'lib/onix/apa_product.rb', line 126

def supplier_website=(str)
  website_set(12, str)
end

#supply_countryObject

retrieve the supply country code



326
327
328
329
# File 'lib/onix/apa_product.rb', line 326

def supply_country
  composite = product.supplier_details.first
  composite.nil? ? nil : composite.supply_to_country
end

#supply_country=(str) ⇒ Object

set a new supply country code



332
333
334
335
# File 'lib/onix/apa_product.rb', line 332

def supply_country=(str)
  composite = find_or_create_supply_detail
  composite.supply_to_country = str
end

#thicknessObject

retrieve the thickness of the product

If APAProduct#measurement_system is metric, these will be in mm, otherwise they will be in inches.



493
494
495
496
# File 'lib/onix/apa_product.rb', line 493

def thickness
  # TODO: auto unit conversion
  measurement(3).andand.measurement
end

#thickness=(value) ⇒ Object

set the thickness of the product

If APAProduct#measurement_system is metric, this should be in mm, otherwise it will be in inches.



503
504
505
506
507
508
509
# File 'lib/onix/apa_product.rb', line 503

def thickness=(value)
  if measurement_system == :metric
    measurement_set(3,value, "mm")
  elsif measurement_system == :imperial
    measurement_set(3,value, "in")
  end
end

#thumbnail_urlObject

retrieve the url to the product thumbnail



194
195
196
# File 'lib/onix/apa_product.rb', line 194

def thumbnail_url
  media_file(7).andand.media_file_link
end

#thumbnail_url=(url) ⇒ Object

set the url to the product cover image



199
200
201
202
203
# File 'lib/onix/apa_product.rb', line 199

def thumbnail_url=(url)
  # 7 - thumbnail image
  # 1 - URI
  media_file_set(7,1,url)
end

#titleObject

retrieve the current title



69
70
71
72
73
74
75
76
# File 'lib/onix/apa_product.rb', line 69

def title
  composite = product.titles.first
  if composite.nil?
    nil
  else
    composite.title_text || composite.title_without_prefix
  end
end

#title=(str) ⇒ Object

set a new title



79
80
81
82
83
84
85
86
87
# File 'lib/onix/apa_product.rb', line 79

def title=(str)
  composite = product.titles.first
  if composite.nil?
    composite =  ONIX::Title.new
    composite.title_type = 1
    product.titles << composite
  end
  composite.title_text = str
end

#weightObject

retrieve the weight of the product

If APAProduct#measurement_system is metric, these will be in grams, otherwise they will be in ounces.



470
471
472
473
# File 'lib/onix/apa_product.rb', line 470

def weight
  # TODO: auto unit conversion
  measurement(8).andand.measurement
end

#weight=(value) ⇒ Object

set the weight of the product

If APAProduct#measurement_system is metric, this should be in grams, otherwise it will be in ounces.



480
481
482
483
484
485
486
# File 'lib/onix/apa_product.rb', line 480

def weight=(value)
  if measurement_system == :metric
    measurement_set(8,value, "gr")
  elsif measurement_system == :imperial
    measurement_set(8,value, "oz")
  end
end

#widthObject

retrieve the width of the product

If APAProduct#measurement_system is metric, these will be in mm, otherwise they will be in inches.



447
448
449
450
# File 'lib/onix/apa_product.rb', line 447

def width
  # TODO: auto unit conversion
  measurement(2).andand.measurement
end

#width=(value) ⇒ Object

set the width of the product

If APAProduct#measurement_system is metric, this should be in mm, otherwise it will be in inches.



457
458
459
460
461
462
463
# File 'lib/onix/apa_product.rb', line 457

def width=(value)
  if measurement_system == :metric
    measurement_set(2,value, "mm")
  elsif measurement_system == :imperial
    measurement_set(2,value, "in")
  end
end