onix2 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (240) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG +209 -0
  3. data/README.markdown +69 -0
  4. data/TODO +14 -0
  5. data/dtd/2.1r3/iso-amsa.ent +173 -0
  6. data/dtd/2.1r3/iso-amsb.ent +146 -0
  7. data/dtd/2.1r3/iso-amsc.ent +49 -0
  8. data/dtd/2.1r3/iso-amsn.ent +117 -0
  9. data/dtd/2.1r3/iso-amso.ent +77 -0
  10. data/dtd/2.1r3/iso-amsr.ent +205 -0
  11. data/dtd/2.1r3/iso-box.ent +67 -0
  12. data/dtd/2.1r3/iso-cyr1.ent +94 -0
  13. data/dtd/2.1r3/iso-cyr2.ent +53 -0
  14. data/dtd/2.1r3/iso-dia.ent +41 -0
  15. data/dtd/2.1r3/iso-grk3.ent +70 -0
  16. data/dtd/2.1r3/iso-lat1.ent +89 -0
  17. data/dtd/2.1r3/iso-lat2.ent +148 -0
  18. data/dtd/2.1r3/iso-mfrk.ent +79 -0
  19. data/dtd/2.1r3/iso-mopf.ent +53 -0
  20. data/dtd/2.1r3/iso-mscr.ent +79 -0
  21. data/dtd/2.1r3/iso-num.ent +103 -0
  22. data/dtd/2.1r3/iso-num.old.ent +103 -0
  23. data/dtd/2.1r3/iso-pub.ent +110 -0
  24. data/dtd/2.1r3/iso-tech.ent +183 -0
  25. data/dtd/2.1r3/onix-international.dtd +1012 -0
  26. data/dtd/2.1r3/onix-xhtml.elt +672 -0
  27. data/dtd/2.1r3/reference.elt +4758 -0
  28. data/dtd/2.1r3/xhtml-special.ent +79 -0
  29. data/dtd/2.1r3/xhtml-symbol.ent +242 -0
  30. data/lib/onix2.rb +85 -0
  31. data/lib/onix2/addressee_identifier.rb +29 -0
  32. data/lib/onix2/apa_product.rb +785 -0
  33. data/lib/onix2/audience_range.rb +37 -0
  34. data/lib/onix2/code_list_extractor.rb +69 -0
  35. data/lib/onix2/contributor.rb +55 -0
  36. data/lib/onix2/discount_coded.rb +29 -0
  37. data/lib/onix2/header.rb +68 -0
  38. data/lib/onix2/imprint.rb +31 -0
  39. data/lib/onix2/language.rb +29 -0
  40. data/lib/onix2/lists.rb +134 -0
  41. data/lib/onix2/market_representation.rb +38 -0
  42. data/lib/onix2/measure.rb +29 -0
  43. data/lib/onix2/media_file.rb +33 -0
  44. data/lib/onix2/other_text.rb +35 -0
  45. data/lib/onix2/price.rb +47 -0
  46. data/lib/onix2/product.rb +97 -0
  47. data/lib/onix2/product_identifier.rb +27 -0
  48. data/lib/onix2/publisher.rb +33 -0
  49. data/lib/onix2/reader.rb +157 -0
  50. data/lib/onix2/sales_restriction.rb +25 -0
  51. data/lib/onix2/sales_rights.rb +28 -0
  52. data/lib/onix2/sender_identifier.rb +29 -0
  53. data/lib/onix2/series.rb +28 -0
  54. data/lib/onix2/series_identifier.rb +27 -0
  55. data/lib/onix2/simple_product.rb +47 -0
  56. data/lib/onix2/stock.rb +29 -0
  57. data/lib/onix2/subject.rb +33 -0
  58. data/lib/onix2/supply_detail.rb +53 -0
  59. data/lib/onix2/title.rb +33 -0
  60. data/lib/onix2/version.rb +3 -0
  61. data/lib/onix2/website.rb +29 -0
  62. data/lib/onix2/writer.rb +86 -0
  63. data/spec/addressee_identifier_spec.rb +33 -0
  64. data/spec/apa_product_spec.rb +116 -0
  65. data/spec/audience_range_spec.rb +44 -0
  66. data/spec/contributor_spec.rb +38 -0
  67. data/spec/discount_coded_spec.rb +34 -0
  68. data/spec/header_spec.rb +153 -0
  69. data/spec/imprint_spec.rb +31 -0
  70. data/spec/language_spec.rb +38 -0
  71. data/spec/lists_spec.rb +33 -0
  72. data/spec/market_representation_spec.rb +33 -0
  73. data/spec/measure_spec.rb +38 -0
  74. data/spec/media_file_spec.rb +38 -0
  75. data/spec/other_text_spec.rb +33 -0
  76. data/spec/price_spec.rb +52 -0
  77. data/spec/product_identifier_spec.rb +34 -0
  78. data/spec/product_spec.rb +102 -0
  79. data/spec/publisher_spec.rb +33 -0
  80. data/spec/reader_spec.rb +155 -0
  81. data/spec/sales_restriction_spec.rb +27 -0
  82. data/spec/sender_identifier.rb +33 -0
  83. data/spec/series_identifier_spec.rb +33 -0
  84. data/spec/series_spec.rb +47 -0
  85. data/spec/spec_helper.rb +15 -0
  86. data/spec/stock_spec.rb +39 -0
  87. data/spec/subject_spec.rb +34 -0
  88. data/spec/supply_detail_spec.rb +97 -0
  89. data/spec/title_spec.rb +38 -0
  90. data/spec/website_spec.rb +33 -0
  91. data/spec/writer_spec.rb +78 -0
  92. data/support/codes/001.tsv +10 -0
  93. data/support/codes/002.tsv +5 -0
  94. data/support/codes/003.tsv +7 -0
  95. data/support/codes/005.tsv +13 -0
  96. data/support/codes/006.tsv +76 -0
  97. data/support/codes/007.tsv +123 -0
  98. data/support/codes/008.tsv +7 -0
  99. data/support/codes/009.tsv +7 -0
  100. data/support/codes/010.tsv +34 -0
  101. data/support/codes/011.tsv +11 -0
  102. data/support/codes/012.tsv +11 -0
  103. data/support/codes/013.tsv +7 -0
  104. data/support/codes/014.tsv +4 -0
  105. data/support/codes/015.tsv +13 -0
  106. data/support/codes/016.tsv +6 -0
  107. data/support/codes/017.tsv +90 -0
  108. data/support/codes/018.tsv +3 -0
  109. data/support/codes/019.tsv +7 -0
  110. data/support/codes/020.tsv +0 -0
  111. data/support/codes/021.tsv +31 -0
  112. data/support/codes/022.tsv +9 -0
  113. data/support/codes/023.tsv +9 -0
  114. data/support/codes/024.tsv +11 -0
  115. data/support/codes/025.tsv +29 -0
  116. data/support/codes/026.tsv +75 -0
  117. data/support/codes/027.tsv +75 -0
  118. data/support/codes/028.tsv +8 -0
  119. data/support/codes/029.tsv +16 -0
  120. data/support/codes/030.tsv +15 -0
  121. data/support/codes/031.tsv +3 -0
  122. data/support/codes/032.tsv +2 -0
  123. data/support/codes/033.tsv +36 -0
  124. data/support/codes/034.tsv +14 -0
  125. data/support/codes/035.tsv +6 -0
  126. data/support/codes/036.tsv +3 -0
  127. data/support/codes/037.tsv +6 -0
  128. data/support/codes/038.tsv +36 -0
  129. data/support/codes/039.tsv +8 -0
  130. data/support/codes/040.tsv +6 -0
  131. data/support/codes/041.tsv +6 -0
  132. data/support/codes/042.tsv +16 -0
  133. data/support/codes/043.tsv +4 -0
  134. data/support/codes/044.tsv +13 -0
  135. data/support/codes/045.tsv +12 -0
  136. data/support/codes/046.tsv +3 -0
  137. data/support/codes/047.tsv +4 -0
  138. data/support/codes/048.tsv +11 -0
  139. data/support/codes/049.tsv +84 -0
  140. data/support/codes/050.tsv +8 -0
  141. data/support/codes/051.tsv +27 -0
  142. data/support/codes/052.tsv +1 -0
  143. data/support/codes/053.tsv +3 -0
  144. data/support/codes/054.tsv +23 -0
  145. data/support/codes/055.tsv +13 -0
  146. data/support/codes/056.tsv +2 -0
  147. data/support/codes/057.tsv +5 -0
  148. data/support/codes/058.tsv +21 -0
  149. data/support/codes/059.tsv +4 -0
  150. data/support/codes/060.tsv +2 -0
  151. data/support/codes/061.tsv +3 -0
  152. data/support/codes/062.tsv +5 -0
  153. data/support/codes/063.tsv +0 -0
  154. data/support/codes/064.tsv +13 -0
  155. data/support/codes/065.tsv +25 -0
  156. data/support/codes/066.tsv +4 -0
  157. data/support/codes/067.tsv +2 -0
  158. data/support/codes/068.tsv +15 -0
  159. data/support/codes/069.tsv +4 -0
  160. data/support/codes/070.tsv +2 -0
  161. data/support/codes/071.tsv +9 -0
  162. data/support/codes/072.tsv +7 -0
  163. data/support/codes/073.tsv +36 -0
  164. data/support/codes/074.tsv +489 -0
  165. data/support/codes/075.tsv +2 -0
  166. data/support/codes/076.tsv +12 -0
  167. data/support/codes/077.tsv +19 -0
  168. data/support/codes/078.tsv +148 -0
  169. data/support/codes/079.tsv +17 -0
  170. data/support/codes/080.tsv +19 -0
  171. data/support/codes/081.tsv +11 -0
  172. data/support/codes/082.tsv +17 -0
  173. data/support/codes/083.tsv +68 -0
  174. data/support/codes/084.tsv +10 -0
  175. data/support/codes/085.tsv +23 -0
  176. data/support/codes/086.tsv +5 -0
  177. data/support/codes/087.tsv +6 -0
  178. data/support/codes/088.tsv +0 -0
  179. data/support/codes/089.tsv +1 -0
  180. data/support/codes/090.tsv +11 -0
  181. data/support/codes/091.tsv +248 -0
  182. data/support/codes/092.tsv +7 -0
  183. data/support/codes/093.tsv +13 -0
  184. data/support/codes/094.tsv +3 -0
  185. data/support/codes/095.tsv +3 -0
  186. data/support/codes/096.tsv +185 -0
  187. data/support/codes/097.tsv +1 -0
  188. data/support/codes/098.tsv +21 -0
  189. data/support/codes/099.tsv +24 -0
  190. data/support/codes/100.tsv +4 -0
  191. data/support/codes/101.tsv +2 -0
  192. data/support/codes/102.tsv +3 -0
  193. data/support/codes/121.tsv +127 -0
  194. data/support/codes/138.tsv +6 -0
  195. data/support/codes/139.tsv +70 -0
  196. data/support/codes/140.tsv +7 -0
  197. data/support/codes/141.tsv +10 -0
  198. data/support/codes/142.tsv +12 -0
  199. data/support/codes/143.tsv +7 -0
  200. data/support/codes/144.tsv +4 -0
  201. data/support/codes/145.tsv +5 -0
  202. data/support/codes/146.tsv +3 -0
  203. data/support/codes/147.tsv +7 -0
  204. data/support/codes/148.tsv +3 -0
  205. data/support/codes/149.tsv +4 -0
  206. data/support/codes/150.tsv +124 -0
  207. data/support/codes/151.tsv +7 -0
  208. data/support/codes/152.tsv +2 -0
  209. data/support/codes/153.tsv +14 -0
  210. data/support/codes/154.tsv +9 -0
  211. data/support/codes/155.tsv +5 -0
  212. data/support/codes/156.tsv +4 -0
  213. data/support/codes/157.tsv +4 -0
  214. data/support/codes/158.tsv +24 -0
  215. data/support/codes/159.tsv +6 -0
  216. data/support/codes/160.tsv +0 -0
  217. data/support/codes/161.tsv +3 -0
  218. data/support/codes/162.tsv +3 -0
  219. data/support/codes/163.tsv +7 -0
  220. data/support/codes/164.tsv +2 -0
  221. data/support/codes/165.tsv +2 -0
  222. data/support/codes/166.tsv +2 -0
  223. data/support/codes/167.tsv +3 -0
  224. data/support/codes/168.tsv +2 -0
  225. data/support/codes/169.tsv +3 -0
  226. data/support/codes/170.tsv +0 -0
  227. data/support/codes/171.tsv +2 -0
  228. data/support/codes/172.tsv +1 -0
  229. data/support/codes/173.tsv +2 -0
  230. data/support/codes/174.tsv +2 -0
  231. data/support/codes/175.tsv +175 -0
  232. data/support/codes/176.tsv +12 -0
  233. data/support/codes/177.tsv +2 -0
  234. data/support/codes/178.tsv +17 -0
  235. data/support/entities.txt +1499 -0
  236. data/support/extract.rb +25 -0
  237. data/support/switch-onix-2.1-short-to-reference.xsl +24 -0
  238. data/support/switch-onix-tagnames-1.1.xsl +25 -0
  239. data/support/switch-onix-tagnames-2.0.xsl +37 -0
  240. metadata +440 -0
@@ -0,0 +1,38 @@
1
+ # coding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe ONIX2::Language do
6
+
7
+ Given(:doc) { load_xml "language.xml" }
8
+
9
+ describe "should correctly convert to a string" do
10
+ Given(:lan) { ONIX2::Language.from_xml(doc) }
11
+ Then { lan.to_xml.to_s.start_with? "<Language>" }
12
+ end
13
+
14
+ describe "should provide read access to first level attributes" do
15
+ Given(:lan) { ONIX2::Language.from_xml(doc) }
16
+
17
+ Then { lan.language_role == 1 }
18
+ Then { lan.language_code == "eng" }
19
+ Then { lan.country_code == "US" }
20
+ end
21
+
22
+ context "should provide write access to first level attributes" do
23
+ Given(:lan) { ONIX2::Language.new }
24
+ describe :language_role= do
25
+ When { lan.language_role = 2 }
26
+ Then { lan.to_xml.to_s.include? "<LanguageRole>02</LanguageRole>" }
27
+ end
28
+ describe :language_code= do
29
+ When { lan.language_code = "aar" }
30
+ Then { lan.to_xml.to_s.include? "<LanguageCode>aar</LanguageCode>" }
31
+ end
32
+ describe :country_code= do
33
+ When { lan.country_code = "AD" }
34
+ Then { lan.to_xml.to_s.include? "<CountryCode>AD</CountryCode>" }
35
+ end
36
+ end
37
+
38
+ end
@@ -0,0 +1,33 @@
1
+ # coding: utf-8
2
+
3
+ require File.dirname(__FILE__) + '/spec_helper.rb'
4
+
5
+ describe ONIX2::Lists, "list method" do
6
+
7
+ it "should return a hash containing the ProductForm code list" do
8
+ forms = ONIX2::Lists.list(7)
9
+ expect(forms).to be_a(Hash)
10
+ expect(forms["BB"]).to be_eql("Hardback")
11
+ end
12
+
13
+ end
14
+
15
+ describe ONIX2::Lists, "product_form shortcut method" do
16
+
17
+ it "should return a hash containing the ProductForm code list" do
18
+ forms = ONIX2::Lists.product_form
19
+ expect(forms).to be_a(Hash)
20
+ expect(forms["BB"]).to be_eql("Hardback")
21
+ end
22
+
23
+ end
24
+
25
+ describe ONIX2::Lists, "PRODUCT_FORM shortcut constant" do
26
+
27
+ it "should return a hash containing the ProductForm code list" do
28
+ forms = ONIX2::Lists::PRODUCT_FORM
29
+ expect(forms).to be_a(Hash)
30
+ expect(forms["BB"]).to be_eql("Hardback")
31
+ end
32
+
33
+ end
@@ -0,0 +1,33 @@
1
+ # coding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe ONIX2::MarketRepresentation do
6
+
7
+ Given(:doc) { load_xml "market_representation.xml" }
8
+
9
+ describe "should correctly convert to a string" do
10
+ Given(:rep) { ONIX2::MarketRepresentation.from_xml(doc) }
11
+ Then { rep.to_xml.to_s.start_with? "<MarketRepresentation>" }
12
+ end
13
+
14
+ describe "should provide read access to first level attributes" do
15
+ Given(:rep) { ONIX2::MarketRepresentation.from_xml(doc) }
16
+
17
+ Then { rep.agent_name == "Allen & Unwin" }
18
+ Then { rep.agent_role == 7 }
19
+ end
20
+
21
+ context "should provide write access to first level attributes" do
22
+ Given(:rep) { ONIX2::MarketRepresentation.new }
23
+ describe :agent_name= do
24
+ When { rep.agent_name = "Rainbow Book Agencies" }
25
+ Then { rep.to_xml.to_s.include? "<AgentName>Rainbow Book Agencies</AgentName>" }
26
+ end
27
+ describe :agent_role= do
28
+ When { rep.agent_role = 3 }
29
+ Then { rep.to_xml.to_s.include? "<AgentRole>03</AgentRole>" }
30
+ end
31
+ end
32
+
33
+ end
@@ -0,0 +1,38 @@
1
+ # coding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe ONIX2::Measure do
6
+
7
+ Given(:doc) { load_xml "measure.xml" }
8
+
9
+ describe "should correctly convert to a string" do
10
+ Given(:m) { ONIX2::Measure.from_xml(doc) }
11
+ Then { m.to_xml.to_s.start_with? "<Measure>" }
12
+ end
13
+
14
+ describe "should provide read access to first level attributes" do
15
+ Given(:m) { ONIX2::Measure.from_xml(doc) }
16
+
17
+ Then { m.measure_type_code == 1 }
18
+ Then { m.measurement == 210 }
19
+ Then { m.measure_unit_code == "mm" }
20
+ end
21
+
22
+ context "should provide write access to first level attributes" do
23
+ Given(:m) { ONIX2::Measure.new }
24
+ describe :measure_type_code= do
25
+ When { m.measure_type_code = 1 }
26
+ Then { m.to_xml.to_s.include? "<MeasureTypeCode>01</MeasureTypeCode>" }
27
+ end
28
+ describe :measurement= do
29
+ When { m.measurement = 300 }
30
+ Then { m.to_xml.to_s.include? "<Measurement>300</Measurement>" }
31
+ end
32
+ describe :measure_unit_code= do
33
+ When { m.measure_unit_code = "mm" }
34
+ Then { m.to_xml.to_s.include? "<MeasureUnitCode>mm</MeasureUnitCode>" }
35
+ end
36
+ end
37
+
38
+ end
@@ -0,0 +1,38 @@
1
+ # coding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe ONIX2::MediaFile do
6
+
7
+ Given(:doc) { load_xml "media_file.xml" }
8
+
9
+ describe "should correctly convert to a string" do
10
+ Given(:mf) { ONIX2::MediaFile.from_xml(doc) }
11
+ Then { mf.to_xml.to_s.start_with? "<MediaFile>" }
12
+ end
13
+
14
+ describe "should provide read access to first level attributes" do
15
+ Given(:mf) { ONIX2::MediaFile.from_xml(doc) }
16
+
17
+ Then { mf.media_file_type_code == 4 }
18
+ Then { mf.media_file_link_type_code == 1 }
19
+ Then { mf.media_file_link == "http://www.allenandunwin.com/BookCovers/resized_9788888028729_224_297_FitSquare.jpg" }
20
+ end
21
+
22
+ context "should provide write access to first level attributes" do
23
+ Given(:mf) { ONIX2::MediaFile.new }
24
+ describe :media_file_type_code= do
25
+ When { mf.media_file_type_code = 2 }
26
+ Then { mf.to_xml.to_s.include? "<MediaFileTypeCode>02</MediaFileTypeCode>" }
27
+ end
28
+ describe :media_file_link_type_code= do
29
+ When { mf.media_file_link_type_code = 1 }
30
+ Then { mf.to_xml.to_s.include? "<MediaFileLinkTypeCode>01</MediaFileLinkTypeCode>" }
31
+ end
32
+ describe :media_file_link= do
33
+ When { mf.media_file_link = "http://www.google.com" }
34
+ Then { mf.to_xml.to_s.include? "<MediaFileLink>http://www.google.com</MediaFileLink>" }
35
+ end
36
+ end
37
+
38
+ end
@@ -0,0 +1,33 @@
1
+ # coding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe ONIX2::OtherText do
6
+
7
+ Given(:doc) { load_xml "other_text.xml" }
8
+
9
+ describe "should correctly convert to a string" do
10
+ Given(:ot) { ONIX2::OtherText.from_xml(doc) }
11
+ Then { ot.to_xml.to_s.start_with? "<OtherText>" }
12
+ end
13
+
14
+ describe "should provide read access to first level attributes" do
15
+ Given(:ot) { ONIX2::OtherText.from_xml(doc) }
16
+
17
+ Then { ot.text_type_code == 2 }
18
+ Then { ot.text.start_with? "A woman" }
19
+ end
20
+
21
+ context "should provide write access to first level attributes" do
22
+ Given(:ot) { ONIX2::OtherText.new }
23
+ describe :text_type_code= do
24
+ When { ot.text_type_code = 2 }
25
+ Then { ot.to_xml.to_s.include? "<TextTypeCode>02</TextTypeCode>" }
26
+ end
27
+ describe :text= do
28
+ When { ot.text = "James Healy" }
29
+ Then { ot.to_xml.to_s.include? "<Text>James Healy</Text>" }
30
+ end
31
+ end
32
+
33
+ end
@@ -0,0 +1,52 @@
1
+ # coding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe ONIX2::Price do
6
+
7
+ Given(:doc) { load_xml "price.xml" }
8
+
9
+ describe "should correctly convert to a string" do
10
+ Given(:p) { ONIX2::Price.from_xml(doc) }
11
+ Then { p.to_xml.to_s.start_with? "<Price>" }
12
+ end
13
+
14
+ describe "should provide read access to first level attributes" do
15
+ Given(:p) { ONIX2::Price.from_xml(doc) }
16
+
17
+ Then { p.price_type_code == 2 }
18
+ Then { p.price_amount == BigDecimal.new("7.5") }
19
+ Then { p.discount_percent == 0.4 }
20
+ end
21
+
22
+ context "should provide write access to first level attributes" do
23
+ Given(:p) { ONIX2::Price.new }
24
+ describe :price_type_code= do
25
+ When { p.price_type_code = 1 }
26
+ Then { p.to_xml.to_s.include? "<PriceTypeCode>01</PriceTypeCode>" }
27
+ end
28
+ describe :price_amount= do
29
+ When { p.price_amount = BigDecimal.new("7.5") }
30
+ Then { p.to_xml.to_s.include? "<PriceAmount>7.5</PriceAmount>" }
31
+ end
32
+ end
33
+
34
+ describe "should provide read access to discount_coded IDs" do
35
+ Given(:p) { ONIX2::Price.from_xml(doc) }
36
+ Then { p.discounts_coded.size == 2 }
37
+ end
38
+
39
+ context "should provide write access to discount_coded IDs" do
40
+ Given(:discount_coded1) { ONIX2::DiscountCoded.new(discount_code_type: 1) }
41
+ Given(:discount_coded2) { ONIX2::DiscountCoded.new(discount_code: "code2") }
42
+ Given(:p) { ONIX2::Price.new }
43
+
44
+ describe :series_identifiers= do
45
+ When { p.discounts_coded = [discount_coded1, discount_coded2] }
46
+
47
+ Then { p.to_xml.to_s.include? "<DiscountCodeType>01</DiscountCodeType>" }
48
+ Then { p.to_xml.to_s.include? "<DiscountCode>code2</DiscountCode>" }
49
+ end
50
+ end
51
+
52
+ end
@@ -0,0 +1,34 @@
1
+ # coding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe ONIX2::ProductIdentifier do
6
+
7
+ Given(:doc) { load_xml "product_identifier.xml" }
8
+
9
+ describe "should correctly convert to a string" do
10
+ Given(:id) { ONIX2::ProductIdentifier.from_xml(doc) }
11
+ Then { id.to_xml.to_s.start_with? "<ProductIdentifier>" }
12
+ end
13
+
14
+ describe "should provide read access to first level attributes" do
15
+ Given(:id) { ONIX2::ProductIdentifier.from_xml(doc) }
16
+
17
+ Then { id.product_id_type == 2 }
18
+ Then { id.id_value == "0858198363" }
19
+ end
20
+
21
+ context "should provide write access to first level attributes" do
22
+ Given(:id) { ONIX2::ProductIdentifier.new }
23
+
24
+ describe :product_id_type= do
25
+ When { id.product_id_type = 2 }
26
+ Then { id.to_xml.to_s.include? "<ProductIDType>02</ProductIDType>" }
27
+ end
28
+ describe :id_value= do
29
+ When { id.id_value = "James" }
30
+ Then { id.to_xml.to_s.include? "<IDValue>James</IDValue>" }
31
+ end
32
+ end
33
+
34
+ end
@@ -0,0 +1,102 @@
1
+ # coding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe ONIX2::Product do
6
+
7
+ Given(:doc) { load_xml "product.xml" }
8
+
9
+ describe "should provide read access to first level attributes" do
10
+ Given(:product) { ONIX2::Product.from_xml(doc) }
11
+
12
+ Then { product.record_reference == "365-9780194351898" }
13
+ Then { product.notification_type == 3 }
14
+ Then { product.product_form == "BC" }
15
+ Then { product.edition_number == 1 }
16
+ Then { product.number_of_pages == 100 }
17
+ Then { product.bic_main_subject == "EB" }
18
+ Then { product.publishing_status == 4 }
19
+ Then { product.publication_date == Date.civil(1998,9,1) }
20
+ Then { product.year_first_published == 1998 }
21
+ # including ye olde, deprecated ones
22
+ Then { product.height == 100 }
23
+ Then { product.width == BigDecimal.new("200.5") }
24
+ Then { product.weight == 300 }
25
+ Then { product.thickness == 300 }
26
+ Then { product.dimensions == "100x200" }
27
+ end
28
+
29
+ describe "should provide read access to product IDs" do
30
+ Given(:product) { ONIX2::Product.from_xml(doc) }
31
+ Then { product.product_identifiers.size == 3 }
32
+ end
33
+
34
+ describe "should provide read access to titles" do
35
+ Given(:product) { ONIX2::Product.from_xml(doc) }
36
+ Then { product.titles.size == 1 }
37
+ end
38
+
39
+ describe "should provide read access to subjects" do
40
+ Given(:product) { ONIX2::Product.from_xml(doc) }
41
+ Then { product.subjects.size == 1 }
42
+ end
43
+
44
+ describe "should provide read access to measurements" do
45
+ Given(:product) { ONIX2::Product.from_xml(doc) }
46
+ Then { product.measurements.size == 1 }
47
+ end
48
+
49
+ context "should provide write access to first level attributes" do
50
+ Given(:product) { ONIX2::Product.new }
51
+ describe :notification_type= do
52
+ When { product.notification_type = 3 }
53
+ Then { product.to_xml.to_s.include? "<NotificationType>03</NotificationType>" }
54
+ end
55
+ describe :record_reference= do
56
+ When { product.record_reference = "365-9780194351898" }
57
+ Then { product.to_xml.to_s.include? "<RecordReference>365-9780194351898</RecordReference>" }
58
+ end
59
+ describe :product_form= do
60
+ When { product.product_form = "BC" }
61
+ Then { product.to_xml.to_s.include? "<ProductForm>BC</ProductForm>" }
62
+ end
63
+ describe :edition_number= do
64
+ When { product.edition_number = 1 }
65
+ Then { product.to_xml.to_s.include? "<EditionNumber>1</EditionNumber>" }
66
+ end
67
+ describe :number_of_pages= do
68
+ When { product.number_of_pages = 100 }
69
+ Then { product.to_xml.to_s.include? "<NumberOfPages>100</NumberOfPages>" }
70
+ end
71
+ describe :bic_main_subject= do
72
+ When { product.bic_main_subject = "EB" }
73
+ Then { product.to_xml.to_s.include? "<BICMainSubject>EB</BICMainSubject>" }
74
+ end
75
+ describe :publishing_status= do
76
+ When { product.publishing_status = 4 }
77
+ Then { product.to_xml.to_s.include? "<PublishingStatus>04</PublishingStatus>" }
78
+ end
79
+ describe :publication_date= do
80
+ When { product.publication_date = Date.civil(1998,9,1) }
81
+ Then { product.to_xml.to_s.include? "<PublicationDate>19980901</PublicationDate>" }
82
+ end
83
+ describe :year_first_published= do
84
+ When { product.year_first_published = 1998 }
85
+ Then { product.to_xml.to_s.include? "<YearFirstPublished>1998</YearFirstPublished>" }
86
+ end
87
+ end
88
+
89
+ end
90
+
91
+ describe ONIX2::Product do
92
+
93
+ Given(:doc) { load_xml "product_invalid_pubdate.xml" }
94
+
95
+ describe "should correctly from_xml files that have an invalid publication date" do
96
+ Given(:product) { ONIX2::Product.from_xml(doc) }
97
+
98
+ Then { product.bic_main_subject == "VXFC1" }
99
+ Then { product.publication_date.nil? }
100
+ end
101
+
102
+ end
@@ -0,0 +1,33 @@
1
+ # coding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe ONIX2::Publisher do
6
+
7
+ Given(:doc) { load_xml "publisher.xml" }
8
+
9
+ describe "should correctly convert to a string" do
10
+ Given(:pub) { ONIX2::Publisher.from_xml(doc) }
11
+ Then { pub.to_xml.to_s.start_with? "<Publisher>" }
12
+ end
13
+
14
+ describe "should provide read access to first level attributes" do
15
+ Given(:pub) { ONIX2::Publisher.from_xml(doc) }
16
+
17
+ Then { pub.publishing_role == 1 }
18
+ Then { pub.publisher_name == "Desbooks Publishing" }
19
+ end
20
+
21
+ context "should provide write access to first level attributes" do
22
+ Given(:pub) { ONIX2::Publisher.new }
23
+ describe :publisher_name= do
24
+ When { pub.publisher_name = "Paulist Press" }
25
+ Then { pub.to_xml.to_s.include? "<PublisherName>Paulist Press</PublisherName>" }
26
+ end
27
+ describe :publishing_role= do
28
+ When { pub.publishing_role = 2 }
29
+ Then { pub.to_xml.to_s.include? "<PublishingRole>02</PublishingRole>" }
30
+ end
31
+ end
32
+
33
+ end