milkfarm-onix 0.8.6 → 0.8.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (192) hide show
  1. data/CHANGELOG +21 -0
  2. data/README.markdown +1 -0
  3. data/lib/onix.rb +4 -17
  4. data/lib/onix/code_list_extractor.rb +69 -0
  5. data/lib/onix/lists.rb +134 -0
  6. data/lib/onix/product.rb +14 -0
  7. data/lib/onix/sl_product.rb +24 -1
  8. data/lib/onix/version.rb +3 -0
  9. data/lib/onix/work_identifier.rb +28 -0
  10. data/spec/apa_product_spec.rb +9 -9
  11. data/spec/audience_range_spec.rb +4 -4
  12. data/spec/contributor_spec.rb +4 -4
  13. data/spec/header_spec.rb +7 -7
  14. data/spec/imprint_spec.rb +4 -4
  15. data/spec/language_spec.rb +4 -4
  16. data/spec/lists_spec.rb +33 -0
  17. data/spec/market_representation_spec.rb +4 -6
  18. data/spec/measure_spec.rb +4 -4
  19. data/spec/media_file_spec.rb +4 -4
  20. data/spec/normaliser_spec.rb +28 -4
  21. data/spec/other_text_spec.rb +4 -4
  22. data/spec/price_spec.rb +4 -4
  23. data/spec/product_identifier_spec.rb +4 -4
  24. data/spec/product_spec.rb +8 -8
  25. data/spec/publisher_spec.rb +4 -4
  26. data/spec/reader_spec.rb +11 -11
  27. data/spec/sales_restriction_spec.rb +4 -5
  28. data/spec/sender_identifier.rb +4 -4
  29. data/spec/series_identifier_spec.rb +4 -4
  30. data/spec/series_spec.rb +4 -4
  31. data/spec/spec_helper.rb +4 -1
  32. data/spec/stock_spec.rb +4 -4
  33. data/spec/subject_spec.rb +4 -5
  34. data/spec/supply_detail_spec.rb +4 -4
  35. data/spec/title_spec.rb +4 -4
  36. data/spec/website_spec.rb +4 -4
  37. data/spec/work_identifier_spec.rb +39 -0
  38. data/spec/writer_spec.rb +7 -7
  39. data/support/codes/001.tsv +10 -0
  40. data/support/codes/002.tsv +5 -0
  41. data/support/codes/003.tsv +7 -0
  42. data/support/codes/005.tsv +13 -0
  43. data/support/codes/006.tsv +76 -0
  44. data/support/codes/007.tsv +123 -0
  45. data/support/codes/008.tsv +7 -0
  46. data/support/codes/009.tsv +7 -0
  47. data/support/codes/010.tsv +34 -0
  48. data/support/codes/011.tsv +11 -0
  49. data/support/codes/012.tsv +11 -0
  50. data/support/codes/013.tsv +7 -0
  51. data/support/codes/014.tsv +4 -0
  52. data/support/codes/015.tsv +13 -0
  53. data/support/codes/016.tsv +6 -0
  54. data/support/codes/017.tsv +90 -0
  55. data/support/codes/018.tsv +3 -0
  56. data/support/codes/019.tsv +7 -0
  57. data/support/codes/020.tsv +0 -0
  58. data/support/codes/021.tsv +31 -0
  59. data/support/codes/022.tsv +9 -0
  60. data/support/codes/023.tsv +9 -0
  61. data/support/codes/024.tsv +11 -0
  62. data/support/codes/025.tsv +29 -0
  63. data/support/codes/026.tsv +75 -0
  64. data/support/codes/027.tsv +75 -0
  65. data/support/codes/028.tsv +8 -0
  66. data/support/codes/029.tsv +16 -0
  67. data/support/codes/030.tsv +15 -0
  68. data/support/codes/031.tsv +3 -0
  69. data/support/codes/032.tsv +2 -0
  70. data/support/codes/033.tsv +36 -0
  71. data/support/codes/034.tsv +14 -0
  72. data/support/codes/035.tsv +6 -0
  73. data/support/codes/036.tsv +3 -0
  74. data/support/codes/037.tsv +6 -0
  75. data/support/codes/038.tsv +36 -0
  76. data/support/codes/039.tsv +8 -0
  77. data/support/codes/040.tsv +6 -0
  78. data/support/codes/041.tsv +6 -0
  79. data/support/codes/042.tsv +16 -0
  80. data/support/codes/043.tsv +4 -0
  81. data/support/codes/044.tsv +13 -0
  82. data/support/codes/045.tsv +12 -0
  83. data/support/codes/046.tsv +3 -0
  84. data/support/codes/047.tsv +4 -0
  85. data/support/codes/048.tsv +11 -0
  86. data/support/codes/049.tsv +84 -0
  87. data/support/codes/050.tsv +8 -0
  88. data/support/codes/051.tsv +27 -0
  89. data/support/codes/052.tsv +1 -0
  90. data/support/codes/053.tsv +3 -0
  91. data/support/codes/054.tsv +23 -0
  92. data/support/codes/055.tsv +13 -0
  93. data/support/codes/056.tsv +2 -0
  94. data/support/codes/057.tsv +5 -0
  95. data/support/codes/058.tsv +21 -0
  96. data/support/codes/059.tsv +4 -0
  97. data/support/codes/060.tsv +2 -0
  98. data/support/codes/061.tsv +3 -0
  99. data/support/codes/062.tsv +5 -0
  100. data/support/codes/063.tsv +0 -0
  101. data/support/codes/064.tsv +13 -0
  102. data/support/codes/065.tsv +25 -0
  103. data/support/codes/066.tsv +4 -0
  104. data/support/codes/067.tsv +2 -0
  105. data/support/codes/068.tsv +15 -0
  106. data/support/codes/069.tsv +4 -0
  107. data/support/codes/070.tsv +2 -0
  108. data/support/codes/071.tsv +9 -0
  109. data/support/codes/072.tsv +7 -0
  110. data/support/codes/073.tsv +36 -0
  111. data/support/codes/074.tsv +489 -0
  112. data/support/codes/075.tsv +2 -0
  113. data/support/codes/076.tsv +12 -0
  114. data/support/codes/077.tsv +19 -0
  115. data/support/codes/078.tsv +148 -0
  116. data/support/codes/079.tsv +17 -0
  117. data/support/codes/080.tsv +19 -0
  118. data/support/codes/081.tsv +11 -0
  119. data/support/codes/082.tsv +17 -0
  120. data/support/codes/083.tsv +68 -0
  121. data/support/codes/084.tsv +10 -0
  122. data/support/codes/085.tsv +23 -0
  123. data/support/codes/086.tsv +5 -0
  124. data/support/codes/087.tsv +6 -0
  125. data/support/codes/088.tsv +0 -0
  126. data/support/codes/089.tsv +1 -0
  127. data/support/codes/090.tsv +11 -0
  128. data/support/codes/091.tsv +248 -0
  129. data/support/codes/092.tsv +7 -0
  130. data/support/codes/093.tsv +13 -0
  131. data/support/codes/094.tsv +3 -0
  132. data/support/codes/095.tsv +3 -0
  133. data/support/codes/096.tsv +185 -0
  134. data/support/codes/097.tsv +1 -0
  135. data/support/codes/098.tsv +21 -0
  136. data/support/codes/099.tsv +24 -0
  137. data/support/codes/100.tsv +4 -0
  138. data/support/codes/101.tsv +2 -0
  139. data/support/codes/102.tsv +3 -0
  140. data/support/codes/121.tsv +127 -0
  141. data/support/codes/138.tsv +6 -0
  142. data/support/codes/139.tsv +70 -0
  143. data/support/codes/140.tsv +7 -0
  144. data/support/codes/141.tsv +10 -0
  145. data/support/codes/142.tsv +12 -0
  146. data/support/codes/143.tsv +7 -0
  147. data/support/codes/144.tsv +4 -0
  148. data/support/codes/145.tsv +5 -0
  149. data/support/codes/146.tsv +3 -0
  150. data/support/codes/147.tsv +7 -0
  151. data/support/codes/148.tsv +3 -0
  152. data/support/codes/149.tsv +4 -0
  153. data/support/codes/150.tsv +124 -0
  154. data/support/codes/151.tsv +7 -0
  155. data/support/codes/152.tsv +2 -0
  156. data/support/codes/153.tsv +14 -0
  157. data/support/codes/154.tsv +9 -0
  158. data/support/codes/155.tsv +5 -0
  159. data/support/codes/156.tsv +4 -0
  160. data/support/codes/157.tsv +4 -0
  161. data/support/codes/158.tsv +24 -0
  162. data/support/codes/159.tsv +6 -0
  163. data/support/codes/160.tsv +0 -0
  164. data/support/codes/161.tsv +3 -0
  165. data/support/codes/162.tsv +3 -0
  166. data/support/codes/163.tsv +7 -0
  167. data/support/codes/164.tsv +2 -0
  168. data/support/codes/165.tsv +2 -0
  169. data/support/codes/166.tsv +2 -0
  170. data/support/codes/167.tsv +3 -0
  171. data/support/codes/168.tsv +2 -0
  172. data/support/codes/169.tsv +3 -0
  173. data/support/codes/170.tsv +0 -0
  174. data/support/codes/171.tsv +2 -0
  175. data/support/codes/172.tsv +1 -0
  176. data/support/codes/173.tsv +2 -0
  177. data/support/codes/174.tsv +2 -0
  178. data/support/codes/175.tsv +175 -0
  179. data/support/codes/176.tsv +12 -0
  180. data/support/codes/177.tsv +2 -0
  181. data/support/codes/178.tsv +17 -0
  182. data/support/switch-onix-2.1-short-to-reference.xsl +3 -2
  183. metadata +226 -38
  184. data/lib/onix/lists/audience_code.rb +0 -17
  185. data/lib/onix/lists/contributor_role.rb +0 -99
  186. data/lib/onix/lists/country_code.rb +0 -257
  187. data/lib/onix/lists/language_code.rb +0 -498
  188. data/lib/onix/lists/language_role.rb +0 -18
  189. data/lib/onix/lists/notification_type.rb +0 -19
  190. data/lib/onix/lists/product_availability.rb +0 -32
  191. data/lib/onix/lists/product_form.rb +0 -99
  192. data/lib/onix/lists/product_form_detail.rb +0 -157
data/CHANGELOG CHANGED
@@ -1,3 +1,24 @@
1
+ v0.8.7 (13 March 2011)
2
+ - Merge yob's commits (code lists, short tags, i18n)
3
+ - Add WorkIdentifier composite (PR.7.15, PR.7.16, PR.7.17)
4
+ - Add EpubType element (PR.23.27)
5
+
6
+ v0.8.6 (17 October 2010)
7
+ - Provide method to set multiple prices
8
+ - eg, General trade and School/Library market
9
+ - Fix reference name of price type qualifier (PR.24.50)
10
+ - 'PriceTypeQualifier' should be 'PriceQualifier'
11
+
12
+ v0.8.5 (Unreleased)
13
+ - Pull yob's dependency yob-roxml
14
+
15
+ v0.8.4 (Unreleased)
16
+ - Handle BISAC main subject category (PR.13.1)
17
+
18
+ ----------------------------------------------------------------------
19
+ - Accidentally diverged from yob's official onix gem version numbers
20
+ ----------------------------------------------------------------------
21
+
1
22
  v0.8.3 (9th September 2010)
2
23
  - Fix for race condition in ONIX::Normaliser
3
24
  - thanks to pixelvixen for reporting
data/README.markdown CHANGED
@@ -45,6 +45,7 @@ view the comments to the following classes:
45
45
  * ONIX::Reader - For reading ONIX files
46
46
  * ONIX::Writer - For writing ONIX files
47
47
  * ONIX::Normaliser - For normalising ONIX files before reading them. Fixes encoding issues, etc
48
+ * ONIX::Lists - For building hashes of code lists from the ONIX spec
48
49
 
49
50
  ## Licensing
50
51
 
data/lib/onix.rb CHANGED
@@ -2,18 +2,11 @@
2
2
 
3
3
  require 'bigdecimal'
4
4
  require 'cgi'
5
+ require 'singleton'
5
6
  require 'roxml'
6
7
  require 'andand'
7
8
 
8
9
  module ONIX
9
- module Version #:nodoc:
10
- Major = 0
11
- Minor = 8
12
- Tiny = 6
13
-
14
- String = [Major, Minor, Tiny].join('.')
15
- end
16
-
17
10
  class Formatters
18
11
  def self.decimal
19
12
  lambda do |val|
@@ -64,6 +57,7 @@ require File.join(File.dirname(__FILE__), "onix", "series_identifier")
64
57
  require File.join(File.dirname(__FILE__), "onix", "series")
65
58
  require File.join(File.dirname(__FILE__), "onix", "set")
66
59
  require File.join(File.dirname(__FILE__), "onix", "title")
60
+ require File.join(File.dirname(__FILE__), "onix", "work_identifier")
67
61
  require File.join(File.dirname(__FILE__), "onix", "website")
68
62
  require File.join(File.dirname(__FILE__), "onix", "contributor")
69
63
  require File.join(File.dirname(__FILE__), "onix", "language")
@@ -83,19 +77,12 @@ require File.join(File.dirname(__FILE__), "onix", "product")
83
77
  require File.join(File.dirname(__FILE__), "onix", "reader")
84
78
  require File.join(File.dirname(__FILE__), "onix", "writer")
85
79
 
86
- # lists
87
- require File.join(File.dirname(__FILE__), "onix", "lists", "product_form")
88
- require File.join(File.dirname(__FILE__), "onix", "lists", "product_availability")
89
- require File.join(File.dirname(__FILE__), "onix", "lists", "country_code")
90
- require File.join(File.dirname(__FILE__), "onix", "lists", "language_code")
91
- require File.join(File.dirname(__FILE__), "onix", "lists", "language_role")
92
- require File.join(File.dirname(__FILE__), "onix", "lists", "notification_type")
93
- require File.join(File.dirname(__FILE__), "onix", "lists", "product_form_detail")
94
-
95
80
  # product wrappers
96
81
  require File.join(File.dirname(__FILE__), "onix", "simple_product")
97
82
  require File.join(File.dirname(__FILE__), "onix", "apa_product")
98
83
  require File.join(File.dirname(__FILE__), "onix", "sl_product")
99
84
 
100
85
  # misc
86
+ require File.join(File.dirname(__FILE__), "onix", "lists")
101
87
  require File.join(File.dirname(__FILE__), "onix", "normaliser")
88
+ require File.join(File.dirname(__FILE__), "onix", "code_list_extractor")
@@ -0,0 +1,69 @@
1
+ # coding: utf-8
2
+
3
+ module ONIX
4
+
5
+ # A utility class that processes the code list XSD from the ONIX spec and
6
+ # creates a set of TSV files. The generated files are used by this library
7
+ # to make hashes of the code lists available to users.
8
+ #
9
+ class CodeListExtractor
10
+
11
+ # Creates a new extractor. Expects the path to a copy of the code lists
12
+ # file from the spec (called ONIX_BookProduct_CodeLists.xsd on my system).
13
+ #
14
+ def initialize(filename)
15
+ raise ArgumentError, "#{filename} not found" unless File.file?(filename)
16
+
17
+ @filename = filename
18
+ end
19
+
20
+ # generate a set of TSV files in the given directory. Creates the directory
21
+ # if it doesn't exist and will overwrite existing files.
22
+ #
23
+ def run(dir)
24
+ FileUtils.mkdir_p(dir) unless File.directory?(dir)
25
+
26
+ each_list do |number, data|
27
+ #puts number
28
+ file = number.to_s.rjust(3, "0") + ".tsv"
29
+ path = File.join(dir, file)
30
+ File.open(path, "w") { |f| f.write data}
31
+ end
32
+ end
33
+
34
+ private
35
+
36
+ def data
37
+ @data ||= File.open(@filename) { |f| f.read }
38
+ end
39
+
40
+ def document
41
+ @document ||= Nokogiri::XML(data)
42
+ @document.remove_namespaces! if @document.namespaces.size > 0
43
+ @document
44
+ end
45
+
46
+ def each_list(&block)
47
+ document.xpath("//simpleType").each do |node|
48
+ list_name = node.xpath("./@name").first.value
49
+ list_number = list_name[/List(\d+)/,1].to_i
50
+ if list_number > 0
51
+ yield list_number, list_data(list_number)
52
+ end
53
+ end
54
+ end
55
+
56
+ def list_data(num)
57
+ str = ""
58
+ nodes = document.xpath("//simpleType[@name='List#{num}']/restriction/enumeration")
59
+ nodes.each do |node|
60
+ code = node.xpath("./@value").first.value
61
+ desc = node.xpath("./annotation/documentation").first.text
62
+ ldesc = node.xpath("./annotation/documentation").last.text
63
+ str += "#{code}\t#{desc}\t#{ldesc}\n"
64
+ end
65
+ str
66
+ end
67
+
68
+ end
69
+ end
data/lib/onix/lists.rb ADDED
@@ -0,0 +1,134 @@
1
+ # coding: utf-8
2
+
3
+ module ONIX
4
+
5
+ # Builds hashes for all code lists in the ONIX spec.
6
+ #
7
+ # Use like so:
8
+ #
9
+ # ONIX::Lists.list(7)
10
+ # => { "BB" => "Hardback", ... }
11
+ #
12
+ # There are also some constants for commonly used lists:
13
+ #
14
+ # ONIX::Lists::PRODUCT_FORM
15
+ # => { "BB" => "Hardback", ... }
16
+ #
17
+ class Lists
18
+ include Singleton
19
+
20
+ # retrieve a hash with the specified code list
21
+ #
22
+ # ONIX::Lists.list(7)
23
+ # => { "BB" => "Hardback", ... }
24
+ #
25
+ def self.list(number)
26
+ self.instance.list(number)
27
+ end
28
+
29
+ # Shortcut to retrieve a common code list
30
+ #
31
+ def self.audience_code
32
+ self.instance.list(28)
33
+ end
34
+
35
+ # Shortcut to retrieve a common code list
36
+ #
37
+ def self.contributor_role
38
+ self.instance.list(17)
39
+ end
40
+
41
+ # Shortcut to retrieve a common code list
42
+ #
43
+ def self.country_code
44
+ self.instance.list(91)
45
+ end
46
+
47
+ # Shortcut to retrieve a common code list
48
+ #
49
+ def self.language_code
50
+ self.instance.list(74)
51
+ end
52
+
53
+ # Shortcut to retrieve a common code list
54
+ #
55
+ def self.language_role
56
+ self.instance.list(22)
57
+ end
58
+
59
+ # Shortcut to retrieve a common code list
60
+ #
61
+ def self.notification_type
62
+ self.instance.list(1)
63
+ end
64
+
65
+ # Shortcut to retrieve a common code list
66
+ #
67
+ def self.product_availability
68
+ self.instance.list(65)
69
+ end
70
+
71
+ # Shortcut to retrieve a common code list
72
+ #
73
+ def self.product_form
74
+ self.instance.list(7)
75
+ end
76
+
77
+ # Shortcut to retrieve a common code list
78
+ #
79
+ def self.product_form_detail
80
+ self.instance.list(78)
81
+ end
82
+
83
+ # return a hash with the data for a single code list.
84
+ #
85
+ # number should be a fixnum specifying the list to retrieve
86
+ #
87
+ # ONIX::Lists.instance.list(7)
88
+ # => { "BB" => "Hardback", ... }
89
+ #
90
+ def list(number)
91
+ cache[number] ||= build_hash(number)
92
+ end
93
+
94
+ private
95
+
96
+ def build_hash(number)
97
+ val = {}
98
+ data(number).each_line do |line|
99
+ code, desc, ldesc = *line.split("\t")
100
+ code = code.to_i if code.to_s.match(/\d+/)
101
+ val[code] = desc
102
+ end
103
+ val
104
+ end
105
+
106
+ def cache
107
+ @cache ||= {}
108
+ end
109
+
110
+ def path(number)
111
+ code_dir = File.dirname(__FILE__) + "/../../support/codes"
112
+ filename = number.to_s.rjust(3, "0") + ".tsv"
113
+ File.join(code_dir, filename)
114
+ end
115
+
116
+ def data(number)
117
+ File.open(path(number)) { |f| f.read }
118
+ end
119
+
120
+ public
121
+
122
+ # These are here for backwards compatability with the onix gem <= 0.8.3
123
+ AUDIENCE_CODE = ONIX::Lists.audience_code
124
+ CONTRIBUTOR_ROLE = ONIX::Lists.contributor_role
125
+ COUNTRY_CODE = ONIX::Lists.country_code
126
+ LANGUAGE_CODE = ONIX::Lists.language_code
127
+ LANGUAGE_ROLE = ONIX::Lists.language_role
128
+ NOTIFICATION_TYPE = ONIX::Lists.notification_type
129
+ PRODUCT_AVAILABILITY = ONIX::Lists.product_availability
130
+ PRODUCT_FORM = ONIX::Lists.product_form
131
+ PRODUCT_FORM_DETAIL = ONIX::Lists.product_form_detail
132
+
133
+ end
134
+ end
data/lib/onix/product.rb CHANGED
@@ -11,9 +11,11 @@ module ONIX
11
11
  xml_accessor :product_identifiers, :from => "ProductIdentifier", :as => [ONIX::ProductIdentifier]
12
12
  xml_accessor :product_form, :from => "ProductForm"
13
13
  xml_accessor :product_form_detail, :from => "ProductFormDetail"
14
+ xml_reader :epub_type, :from => "EpubType"
14
15
  xml_accessor :series, :from => "Series", :as => [ONIX::Series]
15
16
  xml_accessor :sets, :from => "Set", :as => [ONIX::Set]
16
17
  xml_accessor :titles, :from => "Title", :as => [ONIX::Title]
18
+ xml_accessor :work_identifiers, :from => "WorkIdentifier", :as => [ONIX::WorkIdentifier]
17
19
  xml_accessor :websites, :from => "Website", :as => [ONIX::Website]
18
20
  xml_accessor :contributors, :from => "Contributor", :as => [ONIX::Contributor]
19
21
  xml_accessor :edition_number, :from => "EditionNumber", :as => Fixnum
@@ -57,6 +59,7 @@ module ONIX
57
59
  self.series = []
58
60
  self.sets = []
59
61
  self.titles = []
62
+ self.work_identifiers = []
60
63
  self.contributors = []
61
64
  self.websites = []
62
65
  self.subjects = []
@@ -71,5 +74,16 @@ module ONIX
71
74
  self.supply_details = []
72
75
  self.market_representations = []
73
76
  end
77
+
78
+ # TODO: Refactor writer methods using method_missing
79
+ def epub_type=(new_epub_type)
80
+ if new_epub_type.nil? || ONIX::Lists.list(10).keys.include?(new_epub_type)
81
+ # ProductForm code must equal DG if EpubType element is present
82
+ @product_form = "DG"
83
+ @epub_type = new_epub_type
84
+ else
85
+ raise "Invalid EpubType #{new_epub_type}"
86
+ end
87
+ end
74
88
  end
75
89
  end
@@ -7,6 +7,7 @@ module ONIX
7
7
  delegate :copyright_year, :copyright_year=
8
8
  delegate :product_form_detail, :product_form_detail=
9
9
  delegate :basic_main_subject, :basic_main_subject=
10
+ delegate :epub_type, :epub_type=
10
11
 
11
12
  # retrieve the value of a particular ID
12
13
  def series(str)
@@ -52,12 +53,34 @@ module ONIX
52
53
  end
53
54
  end
54
55
 
56
+ # retrieve the work_identifier that matches the given value
57
+ def work_identifier(str)
58
+ product.work_identifiers.find { |obj| obj.id_value == str }
59
+ end
60
+
61
+ # set the value of a particular ID
62
+ def add_work_identifier(value, type = 1)
63
+ # process based on value type
64
+ if value.is_a?(WorkIdentifier)
65
+ str = value.id_value
66
+ work_identifier_obj = value
67
+ else
68
+ str = value
69
+ work_identifier_obj = ONIX::WorkIdentifier.new(:work_id_type => type, :id_value => value)
70
+ end
71
+ # check if exists already
72
+ unless work_identifier(str)
73
+ product.work_identifiers << work_identifier_obj
74
+ end
75
+ end
76
+
55
77
  def add_price(amount, *args)
56
78
  options = args.extract_options!.symbolize_keys
57
79
  # restrict keys to setter methods of format "text="
58
80
  keys = ONIX::Price.instance_methods.delete_if{|x| ! /\w+=$/.match(x)}.map{|x| x.gsub(/=$/, '').to_sym}
59
81
  options.assert_valid_keys(keys)
60
- options.reverse_merge!(:price_type_code => 1)
82
+ # if price_type_code is not set, default to 1
83
+ options.replace({:price_type_code => 1}.merge(options))
61
84
  price = ONIX::Price.new
62
85
  price.price_amount = amount
63
86
  options.each { |k, v| price.send("#{k}=", v) }
@@ -0,0 +1,3 @@
1
+ module ONIX
2
+ VERSION = "0.8.7"
3
+ end
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+
3
+ module ONIX
4
+ class WorkIdentifier
5
+ include ROXML
6
+
7
+ xml_name "WorkIdentifier"
8
+
9
+ xml_reader :work_id_type, :from => "WorkIDType", :as => Fixnum, :to_xml => ONIX::Formatters.two_digit
10
+ xml_accessor :id_type_name, :from => "IDTypeName"
11
+ xml_accessor :id_value, :from => "IDValue"
12
+
13
+ def initialize(options = {})
14
+ options.symbolize_keys!
15
+ self.work_id_type = options[:work_id_type]
16
+ @id_type_name = options[:id_type_name]
17
+ @id_value = options[:id_value]
18
+ end
19
+
20
+ def work_id_type=(new_work_id_type)
21
+ if new_work_id_type.nil? || ::ONIX::Lists.list(16).keys.include?(new_work_id_type)
22
+ @work_id_type = new_work_id_type
23
+ else
24
+ raise "Invalid WorkIDType #{new_work_id_type}"
25
+ end
26
+ end
27
+ end
28
+ end
@@ -3,7 +3,7 @@
3
3
  require File.dirname(__FILE__) + '/spec_helper.rb'
4
4
  require 'date'
5
5
 
6
- context "ONIX::APAProduct" do
6
+ describe "ONIX::APAProduct" do
7
7
 
8
8
  before(:each) do
9
9
  @data_path = File.join(File.dirname(__FILE__),"..","data")
@@ -12,7 +12,7 @@ context "ONIX::APAProduct" do
12
12
  @product_node = @doc.root
13
13
  end
14
14
 
15
- specify "should provide read access to attributes" do
15
+ it "should provide read access to attributes" do
16
16
  @product = ONIX::Product.from_xml(@product_node.to_s)
17
17
  @apa = ONIX::APAProduct.new(@product)
18
18
 
@@ -26,7 +26,7 @@ context "ONIX::APAProduct" do
26
26
  @apa.pack_quantity.should eql(12)
27
27
  end
28
28
 
29
- specify "should provide write access to attributes" do
29
+ it "should provide write access to attributes" do
30
30
  apa = ONIX::APAProduct.new
31
31
 
32
32
  apa.notification_type = 3
@@ -56,8 +56,8 @@ context "ONIX::APAProduct" do
56
56
 
57
57
  end
58
58
 
59
- context ONIX::APAProduct, "series method" do
60
- specify "should set the nested series value on the underlying product class" do
59
+ describe ONIX::APAProduct, "series method" do
60
+ it "should set the nested series value on the underlying product class" do
61
61
  apa = ONIX::APAProduct.new
62
62
 
63
63
  apa.series = "Harry Potter"
@@ -66,7 +66,7 @@ context ONIX::APAProduct, "series method" do
66
66
  end
67
67
  end
68
68
 
69
- context ONIX::APAProduct, "price method" do
69
+ describe ONIX::APAProduct, "price method" do
70
70
  before(:each) do
71
71
  @data_path = File.join(File.dirname(__FILE__),"..","data")
72
72
  file1 = File.join(@data_path, "usd.xml")
@@ -74,7 +74,7 @@ context ONIX::APAProduct, "price method" do
74
74
  @product_node = @doc.root
75
75
  end
76
76
 
77
- specify "should return the first price in the file, regardless of type" do
77
+ it "should return the first price in the file, regardless of type" do
78
78
  @product = ONIX::Product.from_xml(@product_node.to_s)
79
79
  @apa = ONIX::APAProduct.new(@product)
80
80
 
@@ -82,7 +82,7 @@ context ONIX::APAProduct, "price method" do
82
82
  end
83
83
  end
84
84
 
85
- context ONIX::APAProduct, "rrp_exc_sales_tax method" do
85
+ describe ONIX::APAProduct, "rrp_exc_sales_tax method" do
86
86
  before(:each) do
87
87
  @data_path = File.join(File.dirname(__FILE__),"..","data")
88
88
  file1 = File.join(@data_path, "usd.xml")
@@ -90,7 +90,7 @@ context ONIX::APAProduct, "rrp_exc_sales_tax method" do
90
90
  @product_node = @doc.root
91
91
  end
92
92
 
93
- specify "should return the first price in the file of type 1" do
93
+ it "should return the first price in the file of type 1" do
94
94
  @product = ONIX::Product.from_xml(@product_node.to_s)
95
95
  @apa = ONIX::APAProduct.new(@product)
96
96