Class: ONIX::APAProduct

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

Instance Method Summary collapse

Methods inherited from SimpleProduct

#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



152
153
154
# File 'lib/onix/apa_product.rb', line 152

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

#add_bisac_subject(code) ⇒ Object

add a BISAC subject code to the product



163
164
165
# File 'lib/onix/apa_product.rb', line 163

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)



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

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



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

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

#agent_name=(value) ⇒ Object



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

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



146
147
148
149
# File 'lib/onix/apa_product.rb', line 146

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



157
158
159
160
# File 'lib/onix/apa_product.rb', line 157

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



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

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

#cover_urlObject

retrieve the url to the product cover image



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

def cover_url
  media_file(4).andand.media_file_link
end

#cover_url=(url) ⇒ Object

set the url to the product cover image



173
174
175
# File 'lib/onix/apa_product.rb', line 173

def cover_url=(url)
  media_file_set(4,url)
end

#cover_url_hqObject

retrieve the url to the high quality product cover image



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

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



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

def cover_url_hq=(url)
  media_file_set(6,url)
end

#eanObject

retrieve the current EAN



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

def ean
  identifier(3).andand.id_value
end

#ean=(isbn) ⇒ Object

set a new EAN



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

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.



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

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.



420
421
422
423
424
425
426
# File 'lib/onix/apa_product.rb', line 420

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



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

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

#imprint=(str) ⇒ Object

set a new imprint



234
235
236
237
238
239
240
241
# File 'lib/onix/apa_product.rb', line 234

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



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

def isbn10
  identifier(2).andand.id_value
end

#isbn10=(isbn) ⇒ Object

set a new ISBN 10



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

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

#isbn13Object

retrieve the current ISBN 13



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

def isbn13
  identifier(15).andand.id_value
end

#isbn13=(isbn) ⇒ Object

set a new ISBN 13



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

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

#long_descriptionObject

retrieve the long description



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

def long_description
  other_text(3).andand.text
end

#long_description=(t) ⇒ Object

set the long description



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

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

#main_descriptionObject

retrieve the main description



198
199
200
# File 'lib/onix/apa_product.rb', line 198

def main_description
  other_text(1).andand.text
end

#main_description=(t) ⇒ Object

set the main description



203
204
205
# File 'lib/onix/apa_product.rb', line 203

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

#market_publishing_statusObject



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

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

#market_publishing_status=(value) ⇒ Object



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

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



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

def measurement_system
  @measurement_system ||= :metric
end

#measurement_system=(value) ⇒ Object



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

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



342
343
344
345
346
347
348
349
350
# File 'lib/onix/apa_product.rb', line 342

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



353
354
355
356
357
358
359
360
361
# File 'lib/onix/apa_product.rb', line 353

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



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

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



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

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

#product_availabilityObject

retrieve the product availability code



330
331
332
333
# File 'lib/onix/apa_product.rb', line 330

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

#product_availability=(num) ⇒ Object

set a new product availability



336
337
338
339
# File 'lib/onix/apa_product.rb', line 336

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

#proprietary_idObject

retrieve the proprietary ID



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

def proprietary_id
  identifier(1).andand.id_value
end

#proprietary_id=(isbn) ⇒ Object

set a new proprietary ID



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

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

#publisherObject

retrieve the publisher



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

def publisher
  publisher_get(1).andand.publisher_name
end

#publisher=(str) ⇒ Object

set a new publisher



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

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

#publisher_websiteObject

retrieve the current publisher website for this particular product



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

def publisher_website
  website(2).andand.website_link
end

#publisher_website=(str) ⇒ Object

set a new publisher website for this particular product



114
115
116
# File 'lib/onix/apa_product.rb', line 114

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

#rrp_exc_sales_taxObject

retrieve the rrp excluding any sales tax



386
387
388
# File 'lib/onix/apa_product.rb', line 386

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



391
392
393
# File 'lib/onix/apa_product.rb', line 391

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

#rrp_inc_sales_taxObject

retrieve the rrp including any sales tax



396
397
398
# File 'lib/onix/apa_product.rb', line 396

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



401
402
403
# File 'lib/onix/apa_product.rb', line 401

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

#sales_restriction_typeObject

retrieve the sales restriction type



254
255
256
257
# File 'lib/onix/apa_product.rb', line 254

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



260
261
262
263
264
265
266
267
# File 'lib/onix/apa_product.rb', line 260

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



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

def short_description
  other_text(2).andand.text
end

#short_description=(t) ⇒ Object

set the short description



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

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

#subtitleObject

retrieve the current subtitle



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

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

#subtitle=(str) ⇒ Object

set a new subtitle



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

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



306
307
308
309
# File 'lib/onix/apa_product.rb', line 306

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



312
313
314
315
# File 'lib/onix/apa_product.rb', line 312

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

#supplier_faxObject

retrieve the supplier fax number



294
295
296
297
# File 'lib/onix/apa_product.rb', line 294

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



300
301
302
303
# File 'lib/onix/apa_product.rb', line 300

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

#supplier_nameObject

retrieve the supplier name



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

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

#supplier_name=(str) ⇒ Object

set a new supplier name



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

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

#supplier_phoneObject

retrieve the supplier phone number



282
283
284
285
# File 'lib/onix/apa_product.rb', line 282

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



288
289
290
291
# File 'lib/onix/apa_product.rb', line 288

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



119
120
121
# File 'lib/onix/apa_product.rb', line 119

def supplier_website
  website(12).andand.website_link
end

#supplier_website=(str) ⇒ Object

set a new supplier website for this particular product



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

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

#supply_countryObject

retrieve the supply country code



318
319
320
321
# File 'lib/onix/apa_product.rb', line 318

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



324
325
326
327
# File 'lib/onix/apa_product.rb', line 324

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.



479
480
481
482
# File 'lib/onix/apa_product.rb', line 479

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.



489
490
491
492
493
494
495
# File 'lib/onix/apa_product.rb', line 489

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



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

def thumbnail_url
  media_file(7).andand.media_file_link
end

#thumbnail_url=(url) ⇒ Object

set the url to the product cover image



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

def thumbnail_url=(url)
  media_file_set(7,url)
end

#titleObject

retrieve the current title



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

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



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

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.



456
457
458
459
# File 'lib/onix/apa_product.rb', line 456

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.



466
467
468
469
470
471
472
# File 'lib/onix/apa_product.rb', line 466

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.



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

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.



443
444
445
446
447
448
449
# File 'lib/onix/apa_product.rb', line 443

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