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



167
168
169
# File 'lib/onix/apa_product.rb', line 167

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

#add_bisac_subject(code) ⇒ Object

add a BISAC subject code to the product



178
179
180
# File 'lib/onix/apa_product.rb', line 178

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)



150
151
152
153
154
155
156
# File 'lib/onix/apa_product.rb', line 150

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



573
574
575
576
577
# File 'lib/onix/apa_product.rb', line 573

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

#agent_name=(value) ⇒ Object



579
580
581
582
583
584
585
586
# File 'lib/onix/apa_product.rb', line 579

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



161
162
163
164
# File 'lib/onix/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

#bisac_subjectsObject

return an array of BISAC subjects for this title



172
173
174
175
# File 'lib/onix/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

#contributorsObject

retrieve an array of all contributors



144
145
146
# File 'lib/onix/apa_product.rb', line 144

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

#cover_urlObject

retrieve the url to the product cover image



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

def cover_url
  media_file(4).andand.media_file_link
end

#cover_url=(url) ⇒ Object

set the url to the product cover image



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

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



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

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



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

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

#eanObject

retrieve the current EAN



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

def ean
  identifier(3).andand.id_value
end

#ean=(isbn) ⇒ Object

set a new EAN



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

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.



486
487
488
489
# File 'lib/onix/apa_product.rb', line 486

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.



496
497
498
499
500
501
502
# File 'lib/onix/apa_product.rb', line 496

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



249
250
251
252
# File 'lib/onix/apa_product.rb', line 249

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

#imprint=(str) ⇒ Object

set a new imprint



255
256
257
258
259
260
261
262
# File 'lib/onix/apa_product.rb', line 255

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



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

def isbn10
  identifier(2).andand.id_value
end

#isbn10=(isbn) ⇒ Object

set a new ISBN 10



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

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

#isbn13Object

retrieve the current ISBN 13



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

def isbn13
  identifier(15).andand.id_value
end

#isbn13=(isbn) ⇒ Object

set a new ISBN 13



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

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

#long_descriptionObject

retrieve the long description



239
240
241
# File 'lib/onix/apa_product.rb', line 239

def long_description
  other_text(3).andand.text
end

#long_description=(t) ⇒ Object

set the long description



244
245
246
# File 'lib/onix/apa_product.rb', line 244

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

#main_descriptionObject

retrieve the main description



219
220
221
# File 'lib/onix/apa_product.rb', line 219

def main_description
  other_text(1).andand.text
end

#main_description=(t) ⇒ Object

set the main description



224
225
226
# File 'lib/onix/apa_product.rb', line 224

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

#market_countryObject



588
589
590
591
592
# File 'lib/onix/apa_product.rb', line 588

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

#market_country=(value) ⇒ Object



594
595
596
597
598
599
600
601
# File 'lib/onix/apa_product.rb', line 594

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



603
604
605
606
607
# File 'lib/onix/apa_product.rb', line 603

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

#market_publishing_status=(value) ⇒ Object



609
610
611
612
613
614
615
616
# File 'lib/onix/apa_product.rb', line 609

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



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

def measurement_system
  @measurement_system ||= :metric
end

#measurement_system=(value) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/onix/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

#nett_inc_sales_taxObject

retrieve the nett price including any sales tax



439
440
441
# File 'lib/onix/apa_product.rb', line 439

def nett_inc_sales_tax
  price_get(7).andand.price_amount
end

#nett_inc_sales_tax=(num) ⇒ Object

set the rrp including any sales tax



444
445
446
# File 'lib/onix/apa_product.rb', line 444

def nett_inc_sales_tax=(num)
  price_set(7, num)
end

#on_handObject

retrieve the number in stock



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

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



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

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



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

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



396
397
398
399
400
401
402
403
404
# File 'lib/onix/apa_product.rb', line 396

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

#pack_quantityObject

retrieve the supplier phone number



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

def pack_quantity
  composite = product.supply_details.first
  composite.nil? ? nil : composite.pack_quantity
end

#pack_quantity=(val) ⇒ Object

set a new supplier phone number



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

def pack_quantity=(val)
  composite = find_or_create_supply_detail
  composite.pack_quantity = val.to_i
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



477
478
479
# File 'lib/onix/apa_product.rb', line 477

def price
  price_get(nil).andand.price_amount
end

#product_availabilityObject

retrieve the product availability code



351
352
353
354
# File 'lib/onix/apa_product.rb', line 351

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

#product_availability=(num) ⇒ Object

set a new product availability



357
358
359
360
# File 'lib/onix/apa_product.rb', line 357

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

#proprietary_idObject

retrieve the proprietary ID



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

def proprietary_id
  identifier(1).andand.id_value
end

#proprietary_id=(isbn) ⇒ Object

set a new proprietary ID



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

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

#proprietry_discount_code_for_rrpObject

retrieve the discount code that describes the rrp in this file



449
450
451
452
453
454
455
# File 'lib/onix/apa_product.rb', line 449

def proprietry_discount_code_for_rrp
  price    = price_get(2)
  return nil if price.nil?

  discount = price.discounts_coded.find { |disc| disc.discount_code_type == 2 }
  discount.andand.discount_code
end

#proprietry_discount_code_for_rrp=(code) ⇒ Object

set the discount code that describes the rrp in this file



458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
# File 'lib/onix/apa_product.rb', line 458

def proprietry_discount_code_for_rrp=(code)
  price    = price_get(2)
  if price.nil?
    self.rrp_inc_sales_tax = 0
    price    = price_get(2)
  end

  discount = price.discounts_coded.find { |disc| disc.discount_code_type == 2 }

  if discount.nil?
    discount = ONIX::DiscountCoded.new
    discount.discount_code_type = 2
    price.discounts_coded << discount
  end
  discount.discount_code = code
end

#publisherObject

retrieve the publisher



265
266
267
# File 'lib/onix/apa_product.rb', line 265

def publisher
  publisher_get(1).andand.publisher_name
end

#publisher=(str) ⇒ Object

set a new publisher



270
271
272
# File 'lib/onix/apa_product.rb', line 270

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

#publisher_websiteObject

retrieve the current publisher website for this particular product



124
125
126
# File 'lib/onix/apa_product.rb', line 124

def publisher_website
  website(2).andand.website_link
end

#publisher_website=(str) ⇒ Object

set a new publisher website for this particular product



129
130
131
# File 'lib/onix/apa_product.rb', line 129

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

#rrp_exc_sales_taxObject

retrieve the rrp excluding any sales tax



419
420
421
# File 'lib/onix/apa_product.rb', line 419

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



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

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

#rrp_inc_sales_taxObject

retrieve the rrp including any sales tax



429
430
431
# File 'lib/onix/apa_product.rb', line 429

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



434
435
436
# File 'lib/onix/apa_product.rb', line 434

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

#sales_restriction_typeObject

retrieve the sales restriction type



275
276
277
278
# File 'lib/onix/apa_product.rb', line 275

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



281
282
283
284
285
286
287
288
# File 'lib/onix/apa_product.rb', line 281

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

#seriesObject



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

def series
  composite = product.series.first
  composite.andand.title_of_series
end

#series=(val) ⇒ Object



114
115
116
117
118
119
120
121
# File 'lib/onix/apa_product.rb', line 114

def series=(val)
  composite = product.series.first
  if composite.nil?
    composite =  ONIX::Series.new
    product.series << composite
  end
  composite.title_of_series = val.to_s
end

#short_descriptionObject

retrieve the short description



229
230
231
# File 'lib/onix/apa_product.rb', line 229

def short_description
  other_text(2).andand.text
end

#short_description=(t) ⇒ Object

set the short description



234
235
236
# File 'lib/onix/apa_product.rb', line 234

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

#subtitleObject

retrieve the current subtitle



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

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

#subtitle=(str) ⇒ Object

set a new subtitle



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

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



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

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

#supplier_email=(str) ⇒ Object

set a new supplier email address



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

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

#supplier_faxObject

retrieve the supplier fax number



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

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

#supplier_fax=(str) ⇒ Object

set a new supplier fax number



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

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

#supplier_nameObject

retrieve the supplier name



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

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

#supplier_name=(str) ⇒ Object

set a new supplier name



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

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

#supplier_phoneObject

retrieve the supplier phone number



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

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

#supplier_phone=(str) ⇒ Object

set a new supplier phone number



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

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



134
135
136
# File 'lib/onix/apa_product.rb', line 134

def supplier_website
  website(12).andand.website_link
end

#supplier_website=(str) ⇒ Object

set a new supplier website for this particular product



139
140
141
# File 'lib/onix/apa_product.rb', line 139

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

#supply_countryObject

retrieve the supply country code



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

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

#supply_country=(str) ⇒ Object

set a new supply country code



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

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.



555
556
557
558
# File 'lib/onix/apa_product.rb', line 555

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.



565
566
567
568
569
570
571
# File 'lib/onix/apa_product.rb', line 565

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



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

def thumbnail_url
  media_file(7).andand.media_file_link
end

#thumbnail_url=(url) ⇒ Object

set the url to the product cover image



212
213
214
215
216
# File 'lib/onix/apa_product.rb', line 212

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

#titleObject

retrieve the current title



68
69
70
71
72
73
74
75
# File 'lib/onix/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

#title=(str) ⇒ Object

set a new title



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

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.



532
533
534
535
# File 'lib/onix/apa_product.rb', line 532

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.



542
543
544
545
546
547
548
# File 'lib/onix/apa_product.rb', line 542

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.



509
510
511
512
# File 'lib/onix/apa_product.rb', line 509

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.



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

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