milkfarm-onix 0.8.11 → 0.8.12

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,17 @@
1
+ v0.8.12 (28 November 2011)
2
+ - Cherry pick yob's commits from 13 April to 7 November:
3
+ - Relax activesupport dependency to work with rails 3 or 3.1
4
+ - Switch back to the vanilla roxml gem
5
+ - Clarify comments explaining encoding behaviour
6
+ - Add options hash to ONIX::Reader. Only option at this stage is :encoding,
7
+ which allows the user to override the assumed encoding of the input XML
8
+ - API change
9
+ - Skipped yob's implementation of discount_coded
10
+ - It has already been addressed in this fork
11
+ NB: differing syntax discounts_coded v. discount_codeds (this fork uses latter)
12
+ - Add SalesRights (thanks joseph), with ordering adjustment
13
+ - Replace andand with try
14
+
1
15
  v0.8.11 (27 May 2011)
2
16
  - Add Territory, CountryExcluded, TerritoryExcluded to Price composite
3
17
  - Add CountryCode to Price composite
data/README.markdown CHANGED
@@ -21,6 +21,10 @@ ONIX::Normaliser to convert any short tag files to reference tags.
21
21
 
22
22
  ONIX::Writer only generates reference tag ONIX files.
23
23
 
24
+ It baffles me why anyone thought designing two parallel versions of the ONIX
25
+ spec was a good idea. Use reference tags my friends, and let short tags fade
26
+ away into irrelevant obscurity.
27
+
24
28
  ## DTD Loading
25
29
 
26
30
  To correctly handle named entities when reading an ONIX file, this gem attempts
data/lib/onix.rb CHANGED
@@ -4,7 +4,6 @@ require 'bigdecimal'
4
4
  require 'cgi'
5
5
  require 'singleton'
6
6
  require 'roxml'
7
- require 'andand'
8
7
 
9
8
  module ONIX
10
9
  class Formatters
@@ -49,55 +48,61 @@ module ONIX
49
48
  end
50
49
  end
51
50
  end
51
+
52
+ def self.space_separated
53
+ lambda { |val| val.join(" ") if val }
54
+ end
52
55
  end
53
56
  end
54
57
 
55
58
  # helper modules
56
- require File.join(File.dirname(__FILE__), "onix", "list_writer")
57
- require File.join(File.dirname(__FILE__), "onix", "inflector")
58
- require File.join(File.dirname(__FILE__), "onix", "product_identifiers")
59
- require File.join(File.dirname(__FILE__), "onix", "work_identifiers")
60
- require File.join(File.dirname(__FILE__), "onix", "discount_codeds")
59
+ require "onix/list_writer"
60
+ require "onix/inflector"
61
+ require "onix/product_identifiers"
62
+ require "onix/work_identifiers"
63
+ require "onix/discount_codeds"
61
64
 
62
65
  # core files
63
66
  # - ordering is important, classes need to be defined before any
64
67
  # other class can use them
65
- require File.join(File.dirname(__FILE__), "onix", "sender_identifier")
66
- require File.join(File.dirname(__FILE__), "onix", "addressee_identifier")
67
- require File.join(File.dirname(__FILE__), "onix", "header")
68
- require File.join(File.dirname(__FILE__), "onix", "product_identifier")
69
- require File.join(File.dirname(__FILE__), "onix", "series_identifier")
70
- require File.join(File.dirname(__FILE__), "onix", "series")
71
- require File.join(File.dirname(__FILE__), "onix", "set")
72
- require File.join(File.dirname(__FILE__), "onix", "title")
73
- require File.join(File.dirname(__FILE__), "onix", "work_identifier")
74
- require File.join(File.dirname(__FILE__), "onix", "website")
75
- require File.join(File.dirname(__FILE__), "onix", "contributor")
76
- require File.join(File.dirname(__FILE__), "onix", "language")
77
- require File.join(File.dirname(__FILE__), "onix", "subject")
78
- require File.join(File.dirname(__FILE__), "onix", "audience_range")
79
- require File.join(File.dirname(__FILE__), "onix", "imprint")
80
- require File.join(File.dirname(__FILE__), "onix", "publisher")
81
- require File.join(File.dirname(__FILE__), "onix", "other_text")
82
- require File.join(File.dirname(__FILE__), "onix", "media_file")
83
- require File.join(File.dirname(__FILE__), "onix", "sales_restriction")
84
- require File.join(File.dirname(__FILE__), "onix", "stock")
85
- require File.join(File.dirname(__FILE__), "onix", "discount_coded")
86
- require File.join(File.dirname(__FILE__), "onix", "price")
87
- require File.join(File.dirname(__FILE__), "onix", "related_product")
88
- require File.join(File.dirname(__FILE__), "onix", "supply_detail")
89
- require File.join(File.dirname(__FILE__), "onix", "market_representation")
90
- require File.join(File.dirname(__FILE__), "onix", "measure")
91
- require File.join(File.dirname(__FILE__), "onix", "product")
92
- require File.join(File.dirname(__FILE__), "onix", "reader")
93
- require File.join(File.dirname(__FILE__), "onix", "writer")
68
+ require "onix/sender_identifier"
69
+ require "onix/addressee_identifier"
70
+ require "onix/header"
71
+ require "onix/product_identifier"
72
+ require "onix/series_identifier"
73
+ require "onix/series"
74
+ require "onix/set"
75
+ require "onix/title"
76
+ require "onix/work_identifier"
77
+ require "onix/website"
78
+ require "onix/contributor"
79
+ require "onix/language"
80
+ require "onix/subject"
81
+ require "onix/audience_range"
82
+ require "onix/imprint"
83
+ require "onix/publisher"
84
+ require "onix/other_text"
85
+ require "onix/media_file"
86
+ require "onix/sales_restriction"
87
+ require "onix/sales_rights"
88
+ require "onix/not_for_sale"
89
+ require "onix/stock"
90
+ require "onix/discount_coded"
91
+ require "onix/price"
92
+ require "onix/related_product"
93
+ require "onix/supply_detail"
94
+ require "onix/market_representation"
95
+ require "onix/measure"
96
+ require "onix/product"
97
+ require "onix/reader"
98
+ require "onix/writer"
94
99
 
95
100
  # product wrappers
96
- require File.join(File.dirname(__FILE__), "onix", "simple_product")
97
- require File.join(File.dirname(__FILE__), "onix", "apa_product")
98
- require File.join(File.dirname(__FILE__), "onix", "sl_product")
101
+ require "onix/simple_product"
102
+ require "onix/apa_product"
103
+ require "onix/sl_product"
99
104
 
100
105
  # misc
101
- require File.join(File.dirname(__FILE__), "onix", "lists")
102
- require File.join(File.dirname(__FILE__), "onix", "normaliser")
103
- require File.join(File.dirname(__FILE__), "onix", "code_list_extractor")
106
+ require "onix/lists"
107
+ require "onix/normaliser"
108
+ require "onix/code_list_extractor"
@@ -26,7 +26,7 @@ module ONIX
26
26
 
27
27
  # retrieve the current EAN
28
28
  def ean
29
- identifier(3).andand.id_value
29
+ identifier(3).try(:id_value)
30
30
  end
31
31
 
32
32
  # set a new EAN
@@ -36,7 +36,7 @@ module ONIX
36
36
 
37
37
  # retrieve the proprietary ID
38
38
  def proprietary_id
39
- identifier(1).andand.id_value
39
+ identifier(1).try(:id_value)
40
40
  end
41
41
 
42
42
  # set a new proprietary ID
@@ -46,7 +46,7 @@ module ONIX
46
46
 
47
47
  # retrieve the current ISBN 10
48
48
  def isbn10
49
- identifier(2).andand.id_value
49
+ identifier(2).try(:id_value)
50
50
  end
51
51
 
52
52
  # set a new ISBN 10
@@ -56,7 +56,7 @@ module ONIX
56
56
 
57
57
  # retrieve the current ISBN 13
58
58
  def isbn13
59
- identifier(15).andand.id_value
59
+ identifier(15).try(:id_value)
60
60
  end
61
61
 
62
62
  # set a new ISBN 13
@@ -108,7 +108,7 @@ module ONIX
108
108
 
109
109
  def series
110
110
  composite = product.series.first
111
- composite.andand.title_of_series
111
+ composite.try(:title_of_series)
112
112
  end
113
113
 
114
114
  def series=(val)
@@ -122,7 +122,7 @@ module ONIX
122
122
 
123
123
  # retrieve the current publisher website for this particular product
124
124
  def publisher_website
125
- website(2).andand.website_link
125
+ website(2).try(:website_link)
126
126
  end
127
127
 
128
128
  # set a new publisher website for this particular product
@@ -132,7 +132,7 @@ module ONIX
132
132
 
133
133
  # retrieve the current supplier website for this particular product
134
134
  def supplier_website
135
- website(12).andand.website_link
135
+ website(12).try(:website_link)
136
136
  end
137
137
 
138
138
  # set a new supplier website for this particular product
@@ -181,7 +181,7 @@ module ONIX
181
181
 
182
182
  # retrieve the url to the product cover image
183
183
  def cover_url
184
- media_file(4).andand.media_file_link
184
+ media_file(4).try(:media_file_link)
185
185
  end
186
186
 
187
187
  # set the url to the product cover image
@@ -193,7 +193,7 @@ module ONIX
193
193
 
194
194
  # retrieve the url to the high quality product cover image
195
195
  def cover_url_hq
196
- media_file(6).andand.media_file_link
196
+ media_file(6).try(:media_file_link)
197
197
  end
198
198
 
199
199
  # set the url to the high quality product cover image
@@ -205,7 +205,7 @@ module ONIX
205
205
 
206
206
  # retrieve the url to the product thumbnail
207
207
  def thumbnail_url
208
- media_file(7).andand.media_file_link
208
+ media_file(7).try(:media_file_link)
209
209
  end
210
210
 
211
211
  # set the url to the product cover image
@@ -217,7 +217,7 @@ module ONIX
217
217
 
218
218
  # retrieve the main description
219
219
  def main_description
220
- other_text(1).andand.text
220
+ other_text(1).try(:text)
221
221
  end
222
222
 
223
223
  # set the main description
@@ -227,7 +227,7 @@ module ONIX
227
227
 
228
228
  # retrieve the short description
229
229
  def short_description
230
- other_text(2).andand.text
230
+ other_text(2).try(:text)
231
231
  end
232
232
 
233
233
  # set the short description
@@ -237,7 +237,7 @@ module ONIX
237
237
 
238
238
  # retrieve the long description
239
239
  def long_description
240
- other_text(3).andand.text
240
+ other_text(3).try(:text)
241
241
  end
242
242
 
243
243
  # set the long description
@@ -263,7 +263,7 @@ module ONIX
263
263
 
264
264
  # retrieve the publisher
265
265
  def publisher
266
- publisher_get(1).andand.publisher_name
266
+ publisher_get(1).try(:publisher_name)
267
267
  end
268
268
 
269
269
  # set a new publisher
@@ -417,7 +417,7 @@ module ONIX
417
417
 
418
418
  # retrieve the rrp excluding any sales tax
419
419
  def rrp_exc_sales_tax
420
- price_get(1).andand.price_amount
420
+ price_get(1).try(:price_amount)
421
421
  end
422
422
 
423
423
  # set the rrp excluding any sales tax
@@ -427,7 +427,7 @@ module ONIX
427
427
 
428
428
  # retrieve the rrp including any sales tax
429
429
  def rrp_inc_sales_tax
430
- price_get(2).andand.price_amount
430
+ price_get(2).try(:price_amount)
431
431
  end
432
432
 
433
433
  # set the rrp including any sales tax
@@ -438,7 +438,7 @@ module ONIX
438
438
  # just get the first price we can find, regardless of the type.
439
439
  # useful as a backup for reading files from that don't contain a type
440
440
  def price
441
- price_get(nil).andand.price_amount
441
+ price_get(nil).try(:price_amount)
442
442
  end
443
443
 
444
444
  # retrieve the height of the product
@@ -448,7 +448,7 @@ module ONIX
448
448
  #
449
449
  def height
450
450
  # TODO: auto unit conversion
451
- measurement(1).andand.measurement
451
+ measurement(1).try(:measurement)
452
452
  end
453
453
 
454
454
  # set the height of the book
@@ -471,7 +471,7 @@ module ONIX
471
471
  #
472
472
  def width
473
473
  # TODO: auto unit conversion
474
- measurement(2).andand.measurement
474
+ measurement(2).try(:measurement)
475
475
  end
476
476
 
477
477
  # set the width of the product
@@ -494,7 +494,7 @@ module ONIX
494
494
  #
495
495
  def weight
496
496
  # TODO: auto unit conversion
497
- measurement(8).andand.measurement
497
+ measurement(8).try(:measurement)
498
498
  end
499
499
 
500
500
  # set the weight of the product
@@ -517,7 +517,7 @@ module ONIX
517
517
  #
518
518
  def thickness
519
519
  # TODO: auto unit conversion
520
- measurement(3).andand.measurement
520
+ measurement(3).try(:measurement)
521
521
  end
522
522
 
523
523
  # set the thickness of the product
@@ -0,0 +1,21 @@
1
+ # coding: utf-8
2
+
3
+ module ONIX
4
+
5
+ # See also: SalesRights. ONIX 2.1 prefers NotForSale blocks if a product is
6
+ # not for sale, but this can also be specified with SalesRightsType in
7
+ # SalesRights.
8
+ #
9
+ class NotForSale
10
+
11
+ include ROXML
12
+
13
+ xml_name "NotForSale"
14
+ xml_accessor(:rights_countries, :from => "RightsCountry", :to_xml => ONIX::Formatters.space_separated) { |v| v.split if v }
15
+ xml_accessor(:rights_territories, :from => "RightsTerritory", :to_xml => ONIX::Formatters.space_separated) { |v| v.split if v }
16
+ xml_accessor(:product_identifiers, :from => "ProductIdentifier", :as => [ONIX::ProductIdentifier])
17
+ xml_accessor(:publisher_name, :from => "PublisherName")
18
+
19
+ end
20
+
21
+ end
data/lib/onix/product.rb CHANGED
@@ -42,6 +42,8 @@ module ONIX
42
42
  end
43
43
  xml_accessor :copyright_year, :from => "CopyrightYear", :as => Integer
44
44
  xml_accessor :year_first_published, :from => "YearFirstPublished", :as => Fixnum
45
+ xml_accessor :sales_rights, :from => "SalesRights", :as => [ONIX::SalesRights]
46
+ xml_accessor :not_for_sales, :from => "NotForSale", :as => [ONIX::NotForSale]
45
47
  xml_accessor :sales_restrictions, :from => "SalesRestriction", :as => [ONIX::SalesRestriction]
46
48
  xml_accessor :measurements, :from => "Measure", :as => [ONIX::Measure]
47
49
  xml_accessor :related_products, :from => "RelatedProduct", :as => [ONIX::RelatedProduct]
@@ -12,7 +12,7 @@ module ONIX
12
12
 
13
13
  ACCESSOR_METHODS.each do |name, digit|
14
14
  define_method(name) do
15
- find(digit).andand.id_value
15
+ find(digit).try(:id_value)
16
16
  end
17
17
  define_method("#{name}=") do |value|
18
18
  set(digit, value)
data/lib/onix/reader.rb CHANGED
@@ -25,7 +25,7 @@ module ONIX
25
25
  # in a shim that provides simple accessor access to common attributes, pass the
26
26
  # shim class as a second argument
27
27
  #
28
- # reader = ONIX::Reader.new("somefile.xml", ONIX::APAProduct)
28
+ # reader = ONIX::Reader.new("somefile.xml", :product_class => ONIX::APAProduct)
29
29
  #
30
30
  # puts reader.header.inspect
31
31
  #
@@ -39,7 +39,7 @@ module ONIX
39
39
  # As well as accessing the file header, there are handful of other read only
40
40
  # attributes that might be useful
41
41
  #
42
- # reader = ONIX::Reader.new("somefile.xml", ONIX::APAProduct)
42
+ # reader = ONIX::Reader.new("somefile.xml")
43
43
  #
44
44
  # puts reader.version
45
45
  # puts reader.xml_lang
@@ -50,23 +50,50 @@ module ONIX
50
50
  # ONIX spec, and you may need to handle the file differently based on what
51
51
  # version it is.
52
52
  #
53
+ # == File Encoding
54
+ #
55
+ # ONIX::Reader returns all strings as UTF-8. Source file encoding is detected by
56
+ # the encoding declaration at the top of the file, like so:
57
+ #
58
+ # <?xml version="1.0" encoding="iso-8859-1"?>
59
+ #
60
+ # If the encoding declaration is missing the file is assumed to be UTF-8.
61
+ #
62
+ # If the encoding declaration is missing or wrong and the file isn't UTF-8,
63
+ # you can manually set or override it like so:
64
+ #
65
+ # reader = ONIX::Reader.new("somefile.xml", :encoding => "iso-8859-1")
66
+ #
67
+ # If the file contains invalid bytes for the source encoding an exception will
68
+ # be raised. This isn't ideal, but I'm still looking for ways to make this
69
+ # behaviour configurable.
70
+ #
71
+ # If you're running 1.9, you might imagine passing an IO stream that auto
72
+ # transcodes to UTF-8 into ONIX::Reader might have the same effect, but that
73
+ # isn't the case. Nokogiri is used to parse the file, and it seems to ignore
74
+ # IO encoding and just read raw bytes.
75
+ #
53
76
  class Reader
54
77
  include Enumerable
55
78
 
56
79
  attr_reader :header, :release
57
80
 
58
- def initialize(input, product_klass = ::ONIX::Product)
81
+ def initialize(input, *args)
82
+ opts = args.last.kind_of?(Hash) ? args.pop : {}
83
+ if args.size > 0
84
+ ActiveSupport::Deprecation.warn("Passing a klass as ONIX::Reader's second argument is deprecated, use the :product_class option instead", caller)
85
+ end
86
+ @product_klass = opts[:product_class] || args.pop || ::ONIX::Product
87
+
59
88
  if input.kind_of?(String)
60
89
  @file = File.open(input, "r")
61
- @reader = Nokogiri::XML::Reader(@file) { |cfg| cfg.dtdload.noent }
90
+ @reader = Nokogiri::XML::Reader(@file, nil, opts[:encoding]) { |cfg| cfg.dtdload.noent }
62
91
  elsif input.kind_of?(IO)
63
- @reader = Nokogiri::XML::Reader(input) { |cfg| cfg.dtdload.noent }
92
+ @reader = Nokogiri::XML::Reader(input, nil, opts[:encoding]) { |cfg| cfg.dtdload.noent }
64
93
  else
65
94
  raise ArgumentError, "Unable to read from file or IO stream"
66
95
  end
67
96
 
68
- @product_klass = product_klass
69
-
70
97
  @release = find_release
71
98
  @header = find_header
72
99
 
@@ -0,0 +1,19 @@
1
+ # coding: utf-8
2
+
3
+ module ONIX
4
+
5
+ # See also: NotForSale. It's possible to set not for sale here as well.
6
+ #
7
+ class SalesRights
8
+ include ROXML
9
+
10
+ xml_name "SalesRights"
11
+ xml_accessor :sales_rights_type, :from => "SalesRightsType", :as => Fixnum, :to_xml => ONIX::Formatters.two_digit
12
+ xml_accessor(:rights_countries, :from => "RightsCountry", :to_xml => ONIX::Formatters.space_separated) { |v| v.split if v }
13
+ xml_accessor(:rights_territories, :from => "RightsTerritory", :to_xml => ONIX::Formatters.space_separated) { |v| v.split if v }
14
+
15
+ # Deprecated accessors
16
+ xml_accessor(:rights_region, :from => "RightsRegion", :as => [])
17
+
18
+ end
19
+ end
data/lib/onix/series.rb CHANGED
@@ -15,7 +15,7 @@ module ONIX
15
15
 
16
16
  # retrieve the proprietary series ID
17
17
  def proprietary_series_id
18
- series_identifier(1).andand.id_value
18
+ series_identifier(1).try(:id_value)
19
19
  end
20
20
 
21
21
  # set a new proprietary series ID
@@ -25,7 +25,7 @@ module ONIX
25
25
 
26
26
  # retrieve the issn
27
27
  def issn
28
- series_identifier(2).andand.id_value
28
+ series_identifier(2).try(:id_value)
29
29
  end
30
30
 
31
31
  # set a new issn
data/lib/onix/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module ONIX
2
- VERSION = "0.8.11"
2
+ VERSION = "0.8.12"
3
3
  end
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+
3
+ require File.dirname(__FILE__) + '/spec_helper.rb'
4
+
5
+ describe ONIX::NotForSale do
6
+
7
+ before(:each) do
8
+ load_doc_and_root("sales_rights.xml")
9
+ @nfs = @root.at_css("NotForSale")
10
+ end
11
+
12
+
13
+ it "should correctly convert to a string" do
14
+ rep = ONIX::NotForSale.from_xml(@nfs.to_s)
15
+ rep.should produce_the_tag("<NotForSale>")
16
+ end
17
+
18
+
19
+ it "should provide read access to first level attributes" do
20
+ p = ONIX::Product.from_xml(@root.to_s)
21
+ p.not_for_sales[0].rights_countries.should eql(["UK"])
22
+ end
23
+
24
+
25
+ it "should provide write access to first level attributes" do
26
+ nfs = ONIX::NotForSale.new
27
+ nfs.rights_countries = ["UK", "US", "IR"]
28
+ nfs.should include_the_xml("<RightsCountry>UK US IR</RightsCountry>")
29
+ end
30
+
31
+ end
data/spec/reader_spec.rb CHANGED
@@ -12,6 +12,7 @@ describe ONIX::Reader do
12
12
  @entity_file = File.join(@data_path, "entities.xml")
13
13
  @utf_16_file = File.join(@data_path, "utf_16.xml")
14
14
  @iso_8859_1_file = File.join(@data_path, "iso_8859_1.xml")
15
+ @no_encoding_decl_file = File.join(@data_path, "aau.xml")
15
16
  end
16
17
 
17
18
  it "should initialize with a filename" do
@@ -90,19 +91,36 @@ describe ONIX::Reader do
90
91
 
91
92
  it "should transparently convert a iso-8859-1 file to utf-8" do
92
93
  reader = ONIX::Reader.new(@iso_8859_1_file)
93
- product = nil
94
- reader.each do |p|
95
- product = p
96
- end
94
+ reader.each do |product|
95
+ if RUBY_VERSION >= "1.9"
96
+ utf8 = Encoding.find("utf-8")
97
+ product.contributors[0].person_name_inverted.encoding.should eql(utf8)
98
+ end
97
99
 
98
- # ROXML appears to munge the string encodings
99
- if RUBY_VERSION >= "1.9"
100
- utf8 = Encoding.find("utf-8")
101
- product.contributors[0].person_name_inverted.encoding.should eql(utf8)
100
+ product.contributors[0].person_name_inverted.should eql("Küng, Hans")
102
101
  end
102
+ end
103
103
 
104
- product.contributors[0].person_name_inverted.should eql("Küng, Hans")
104
+ # This isn't ideal behaviour, but i'm somewhat hamstrung by nokogiri API. It'd
105
+ # be nice to have the option to replace unrecognised bytes with a valid char.
106
+ it "should raise an exception when an iso-8859-1 file isn't declared as such" do
107
+ reader = ONIX::Reader.new(@no_encoding_decl_file)
108
+ lambda {
109
+ reader.each do |product|
110
+ end
111
+ }.should raise_error(Nokogiri::XML::SyntaxError)
112
+ end
113
+
114
+ it "should transparently convert an iso-8859-1 file to utf-8 when there's no declaration but the user manually specifies iso-8859-1" do
115
+ reader = ONIX::Reader.new(@no_encoding_decl_file, :encoding => "iso-8859-1")
116
+ reader.each do |product|
117
+ if RUBY_VERSION >= "1.9"
118
+ utf8 = Encoding.find("utf-8")
119
+ product.contributors[0].person_name_inverted.encoding.should eql(utf8)
120
+ end
105
121
 
122
+ product.contributors[0].person_name_inverted.should eql("Melo,Patr¡cia")
123
+ end
106
124
  end
107
125
 
108
126
  it "should transparently convert a utf-16 file to utf-8" do
@@ -119,6 +137,19 @@ describe ONIX::Reader do
119
137
  end
120
138
 
121
139
  product.contributors[0].person_name_inverted.should eql("Küng, Hans")
140
+ end
122
141
 
142
+ it "should support returning an APAProduct using deprecated API" do
143
+ reader = ONIX::Reader.new(@file1, ONIX::APAProduct)
144
+ reader.each do |product|
145
+ product.should be_a_kind_of(ONIX::APAProduct)
146
+ end
147
+ end
148
+
149
+ it "should support returning an APAProduct using new API" do
150
+ reader = ONIX::Reader.new(@file1, :product_class => ONIX::APAProduct)
151
+ reader.each do |product|
152
+ product.should be_a_kind_of(ONIX::APAProduct)
153
+ end
123
154
  end
124
155
  end
@@ -0,0 +1,39 @@
1
+ # coding: utf-8
2
+
3
+ require File.dirname(__FILE__) + '/spec_helper.rb'
4
+
5
+ describe ONIX::SalesRights do
6
+
7
+ before(:each) do
8
+ load_doc_and_root("sales_rights.xml")
9
+ @first_right = @root.at_css("SalesRights")
10
+ end
11
+
12
+
13
+ it "should correctly convert to a string" do
14
+ rep = ONIX::SalesRights.from_xml(@first_right.to_s)
15
+ rep.should produce_the_tag("<SalesRights")
16
+ end
17
+
18
+
19
+ it "should provide read access to first level attributes" do
20
+ p = ONIX::Product.from_xml(@root.to_s)
21
+ p.sales_rights[0].sales_rights_type.should eql(1)
22
+ p.sales_rights[1].rights_countries.should eql(["AU", "NZ"])
23
+ end
24
+
25
+
26
+ it "should provide write access to first level attributes" do
27
+ sr = ONIX::SalesRights.new
28
+ sr.sales_rights_type = 2
29
+ sr.should include_the_xml("<SalesRightsType>02</SalesRightsType>")
30
+ sr.rights_territories = ["WORLD"]
31
+ sr.should include_the_xml("<RightsTerritory>WORLD</RightsTerritory>")
32
+ end
33
+
34
+ it "should provide an array for deprecated rights regions" do
35
+ p = ONIX::Product.from_xml(@root.to_s)
36
+ p.sales_rights[2].rights_region.should eql(["001", "002", "003", "004"])
37
+ end
38
+
39
+ end
data/spec/spec_helper.rb CHANGED
@@ -8,3 +8,38 @@ require 'date'
8
8
  require 'stringio'
9
9
  require 'rubygems'
10
10
  require 'onix'
11
+
12
+
13
+ module ONIX::SpecHelpers
14
+
15
+ def load_doc_and_root(subpath)
16
+ data_path = File.join(File.dirname(__FILE__), '..', 'data')
17
+ file1 = File.join(data_path, subpath)
18
+ @doc = Nokogiri::XML::Document.parse(File.read(file1))
19
+ @root = @doc.root
20
+ end
21
+
22
+ end
23
+
24
+ include ONIX::SpecHelpers
25
+
26
+
27
+ RSpec::Matchers.define(:produce_the_tag) do |expected|
28
+ match do |actual|
29
+ actual.to_xml.to_s[0, expected.size] == expected
30
+ end
31
+ end
32
+
33
+ RSpec::Matchers.define(:include_the_xml) do |expected|
34
+ match do |actual|
35
+ actual.to_xml.to_s.include?(expected)
36
+ end
37
+
38
+ failure_message_for_should do |actual|
39
+ "expected '#{actual.to_xml.to_s}' to include the xml '#{expected}'"
40
+ end
41
+
42
+ failure_message_for_should_not do |actual|
43
+ "expected '#{actual.to_xml.to_s}' not to include the xml '#{expected}'"
44
+ end
45
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: milkfarm-onix
3
3
  version: !ruby/object:Gem::Version
4
- hash: 41
4
+ hash: 39
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 8
9
- - 11
10
- version: 0.8.11
9
+ - 12
10
+ version: 0.8.12
11
11
  platform: ruby
12
12
  authors:
13
13
  - James Healy
@@ -16,14 +16,15 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2011-05-27 00:00:00 -07:00
20
- default_executable:
19
+ date: 2011-11-29 00:00:00 Z
21
20
  dependencies:
22
21
  - !ruby/object:Gem::Dependency
23
- version_requirements: &id001 !ruby/object:Gem::Requirement
22
+ name: roxml
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
24
25
  none: false
25
26
  requirements:
26
- - - ">="
27
+ - - ~>
27
28
  - !ruby/object:Gem::Version
28
29
  hash: 15
29
30
  segments:
@@ -31,26 +32,28 @@ dependencies:
31
32
  - 1
32
33
  - 6
33
34
  version: 3.1.6
34
- prerelease: false
35
35
  type: :runtime
36
- requirement: *id001
37
- name: roxml
36
+ version_requirements: *id001
38
37
  - !ruby/object:Gem::Dependency
39
- version_requirements: &id002 !ruby/object:Gem::Requirement
38
+ name: activesupport
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
40
41
  none: false
41
42
  requirements:
42
43
  - - ">="
43
44
  - !ruby/object:Gem::Version
44
- hash: 3
45
+ hash: 1
45
46
  segments:
47
+ - 3
46
48
  - 0
47
- version: "0"
48
- prerelease: false
49
+ - 3
50
+ version: 3.0.3
49
51
  type: :runtime
50
- requirement: *id002
51
- name: i18n
52
+ version_requirements: *id002
52
53
  - !ruby/object:Gem::Dependency
53
- version_requirements: &id003 !ruby/object:Gem::Requirement
54
+ name: i18n
55
+ prerelease: false
56
+ requirement: &id003 !ruby/object:Gem::Requirement
54
57
  none: false
55
58
  requirements:
56
59
  - - ">="
@@ -59,27 +62,27 @@ dependencies:
59
62
  segments:
60
63
  - 0
61
64
  version: "0"
62
- prerelease: false
63
65
  type: :runtime
64
- requirement: *id003
65
- name: andand
66
+ version_requirements: *id003
66
67
  - !ruby/object:Gem::Dependency
67
- version_requirements: &id004 !ruby/object:Gem::Requirement
68
+ name: nokogiri
69
+ prerelease: false
70
+ requirement: &id004 !ruby/object:Gem::Requirement
68
71
  none: false
69
72
  requirements:
70
- - - ">="
73
+ - - ~>
71
74
  - !ruby/object:Gem::Version
72
75
  hash: 7
73
76
  segments:
74
77
  - 1
75
78
  - 4
76
79
  version: "1.4"
77
- prerelease: false
78
80
  type: :runtime
79
- requirement: *id004
80
- name: nokogiri
81
+ version_requirements: *id004
81
82
  - !ruby/object:Gem::Dependency
82
- version_requirements: &id005 !ruby/object:Gem::Requirement
83
+ name: rake
84
+ prerelease: false
85
+ requirement: &id005 !ruby/object:Gem::Requirement
83
86
  none: false
84
87
  requirements:
85
88
  - - ">="
@@ -88,12 +91,12 @@ dependencies:
88
91
  segments:
89
92
  - 0
90
93
  version: "0"
91
- prerelease: false
92
94
  type: :development
93
- requirement: *id005
94
- name: rake
95
+ version_requirements: *id005
95
96
  - !ruby/object:Gem::Dependency
96
- version_requirements: &id006 !ruby/object:Gem::Requirement
97
+ name: rspec
98
+ prerelease: false
99
+ requirement: &id006 !ruby/object:Gem::Requirement
97
100
  none: false
98
101
  requirements:
99
102
  - - ~>
@@ -103,10 +106,8 @@ dependencies:
103
106
  - 2
104
107
  - 1
105
108
  version: "2.1"
106
- prerelease: false
107
109
  type: :development
108
- requirement: *id006
109
- name: rspec
110
+ version_requirements: *id006
110
111
  description: A fork of the original onix gem by James Healy. Differs from original mainly in it's adjustments for the US school/library market as applied in the product wrapper SLProduct.
111
112
  email:
112
113
  - jimmy@deefa.com
@@ -135,6 +136,7 @@ files:
135
136
  - lib/onix/measure.rb
136
137
  - lib/onix/media_file.rb
137
138
  - lib/onix/normaliser.rb
139
+ - lib/onix/not_for_sale.rb
138
140
  - lib/onix/other_text.rb
139
141
  - lib/onix/price.rb
140
142
  - lib/onix/product.rb
@@ -144,6 +146,7 @@ files:
144
146
  - lib/onix/reader.rb
145
147
  - lib/onix/related_product.rb
146
148
  - lib/onix/sales_restriction.rb
149
+ - lib/onix/sales_rights.rb
147
150
  - lib/onix/sender_identifier.rb
148
151
  - lib/onix/series.rb
149
152
  - lib/onix/series_identifier.rb
@@ -350,6 +353,7 @@ files:
350
353
  - spec/measure_spec.rb
351
354
  - spec/media_file_spec.rb
352
355
  - spec/normaliser_spec.rb
356
+ - spec/not_for_sale_spec.rb
353
357
  - spec/other_text_spec.rb
354
358
  - spec/price_spec.rb
355
359
  - spec/product_identifier_spec.rb
@@ -359,6 +363,7 @@ files:
359
363
  - spec/reader_spec.rb
360
364
  - spec/related_product_spec.rb
361
365
  - spec/sales_restriction_spec.rb
366
+ - spec/sales_rights_spec.rb
362
367
  - spec/sender_identifier.rb
363
368
  - spec/series_identifier_spec.rb
364
369
  - spec/series_spec.rb
@@ -373,7 +378,6 @@ files:
373
378
  - spec/work_identifier_spec.rb
374
379
  - spec/work_identifiers_spec.rb
375
380
  - spec/writer_spec.rb
376
- has_rdoc: true
377
381
  homepage: http://github.com/milkfarm/onix
378
382
  licenses: []
379
383
 
@@ -405,10 +409,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
405
409
  requirements: []
406
410
 
407
411
  rubyforge_project:
408
- rubygems_version: 1.5.0
412
+ rubygems_version: 1.8.10
409
413
  signing_key:
410
414
  specification_version: 3
411
- summary: A convient mapping between ruby objects and the ONIX XML specification
415
+ summary: A convenient mapping between Ruby objects and the ONIX XML specification
412
416
  test_files:
413
417
  - spec/apa_product_spec.rb
414
418
  - spec/audience_range_spec.rb
@@ -424,6 +428,7 @@ test_files:
424
428
  - spec/measure_spec.rb
425
429
  - spec/media_file_spec.rb
426
430
  - spec/normaliser_spec.rb
431
+ - spec/not_for_sale_spec.rb
427
432
  - spec/other_text_spec.rb
428
433
  - spec/price_spec.rb
429
434
  - spec/product_identifier_spec.rb
@@ -433,6 +438,7 @@ test_files:
433
438
  - spec/reader_spec.rb
434
439
  - spec/related_product_spec.rb
435
440
  - spec/sales_restriction_spec.rb
441
+ - spec/sales_rights_spec.rb
436
442
  - spec/sender_identifier.rb
437
443
  - spec/series_identifier_spec.rb
438
444
  - spec/series_spec.rb