onix 0.4.7 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. data/CHANGELOG +5 -0
  2. data/lib/onix.rb +51 -17
  3. data/lib/onix/addressee_identifier.rb +1 -1
  4. data/lib/onix/contributor.rb +16 -14
  5. data/lib/onix/header.rb +24 -18
  6. data/lib/onix/imprint.rb +6 -4
  7. data/lib/onix/market_representation.rb +9 -7
  8. data/lib/onix/measure.rb +5 -3
  9. data/lib/onix/media_file.rb +5 -3
  10. data/lib/onix/other_text.rb +8 -6
  11. data/lib/onix/price.rb +8 -6
  12. data/lib/onix/product.rb +39 -24
  13. data/lib/onix/product_identifier.rb +3 -1
  14. data/lib/onix/publisher.rb +7 -5
  15. data/lib/onix/reader.rb +51 -8
  16. data/lib/onix/sales_restriction.rb +3 -1
  17. data/lib/onix/sender_identifier.rb +3 -1
  18. data/lib/onix/simple_product.rb +4 -0
  19. data/lib/onix/stock.rb +2 -0
  20. data/lib/onix/subject.rb +7 -5
  21. data/lib/onix/supply_detail.rb +13 -6
  22. data/lib/onix/title.rb +5 -3
  23. data/lib/onix/website.rb +5 -3
  24. data/spec/contributor_spec.rb +42 -0
  25. data/spec/header_spec.rb +19 -18
  26. data/spec/imprint_spec.rb +39 -0
  27. data/spec/market_representation_spec.rb +41 -0
  28. data/spec/measure_spec.rb +43 -0
  29. data/spec/media_file_spec.rb +42 -0
  30. data/spec/other_text_spec.rb +40 -0
  31. data/spec/price_spec.rb +40 -0
  32. data/spec/product_identifier_spec.rb +40 -0
  33. data/spec/product_spec.rb +17 -16
  34. data/spec/publisher_spec.rb +38 -0
  35. data/spec/sales_restriction_spec.rb +35 -0
  36. data/spec/sender_identifier.rb +40 -0
  37. data/spec/stock_spec.rb +44 -0
  38. data/spec/subject_spec.rb +40 -0
  39. data/spec/supply_detail_spec.rb +50 -0
  40. data/spec/title_spec.rb +43 -0
  41. data/spec/website_spec.rb +41 -0
  42. metadata +25 -14
  43. data/lib/onix/date_type.rb +0 -54
  44. data/lib/onix/decimal_type.rb +0 -49
  45. data/lib/onix/etext_type.rb +0 -44
  46. data/lib/onix/integer_type.rb +0 -43
  47. data/lib/onix/two_digit_type.rb +0 -57
data/CHANGELOG CHANGED
@@ -1,3 +1,8 @@
1
+ v0.5 (2nd March 2009)
2
+ - Switch ROXML dependency from a patched version to vanilla
3
+ - Vanilla ROXML now has all the features we need
4
+ - This change should be transparent to ONIX gem users
5
+
1
6
  v0.4.7 (9th December 2008)
2
7
  - Contributor sub elements should match the order specified in the DTD
3
8
 
@@ -1,19 +1,63 @@
1
1
  require 'rubygems'
2
+ require 'bigdecimal'
3
+ require 'cgi'
2
4
 
3
5
  # ensure we load the correct gem versions
4
- gem 'yob-roxml', '2.1.1'
6
+ gem 'roxml', '2.5.1'
5
7
  gem 'andand'
6
8
 
7
9
  # and now load the actual gems
8
10
  require 'roxml'
9
11
  require 'andand'
10
12
 
11
- # custom xml-mapping node types
12
- require File.join(File.dirname(__FILE__), "onix", "decimal_type")
13
- require File.join(File.dirname(__FILE__), "onix", "etext_type")
14
- require File.join(File.dirname(__FILE__), "onix", "integer_type")
15
- require File.join(File.dirname(__FILE__), "onix", "two_digit_type")
16
- require File.join(File.dirname(__FILE__), "onix", "date_type")
13
+ module ONIX
14
+ module Version #:nodoc:
15
+ Major = 0
16
+ Minor = 5
17
+ Tiny = 0
18
+
19
+ String = [Major, Minor, Tiny].join('.')
20
+ end
21
+
22
+ class Formatters
23
+ def self.decimal
24
+ lambda do |val|
25
+ if val.kind_of?(BigDecimal)
26
+ val.to_s("F")
27
+ else
28
+ val.to_s
29
+ end
30
+ end
31
+ end
32
+
33
+ def self.yyyymmdd
34
+ lambda do |val|
35
+ if val.nil? || !val.respond_to?(:strftime)
36
+ nil
37
+ else
38
+ val.strftime("%Y%m%d")
39
+ end
40
+ end
41
+ end
42
+
43
+ def self.two_digit
44
+ lambda do |val|
45
+ if val.nil?
46
+ nil
47
+ elsif val < 10
48
+ "0#{val}"
49
+ elsif val > 99
50
+ val.to_s[-2,2]
51
+ else
52
+ val.to_s
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
58
+
59
+ # silence some warnings from ROXML
60
+ ROXML::SILENCE_XML_NAME_WARNING = true
17
61
 
18
62
  # core files
19
63
  # - ordering is important, classes need to be defined before any
@@ -48,13 +92,3 @@ require File.join(File.dirname(__FILE__), "onix", "lists", "product_availability
48
92
  require File.join(File.dirname(__FILE__), "onix", "simple_product")
49
93
  require File.join(File.dirname(__FILE__), "onix", "apa_product")
50
94
 
51
- module ONIX
52
- module Version #:nodoc:
53
- Major = 0
54
- Minor = 4
55
- Tiny = 7
56
-
57
- String = [Major, Minor, Tiny].join('.')
58
- end
59
-
60
- end
@@ -2,7 +2,7 @@ module ONIX
2
2
  class AddresseeIdentifier
3
3
  include ROXML
4
4
 
5
- xml_accessor :addressee_id_type, :twodigit, :from => "AddresseeIDType"
5
+ xml_accessor :addressee_id_type, :from => "AddresseeIDType", :as => Fixnum # should be a 2 digit num
6
6
  xml_accessor :id_type_name, :from => "IDTypeName"
7
7
  xml_accessor :id_value, :from => "IDValue"
8
8
  end
@@ -2,21 +2,23 @@ module ONIX
2
2
  class Contributor
3
3
  include ROXML
4
4
 
5
- xml_accessor :sequence_number, :from => "SequenceNumber"
5
+ xml_name "Contributor"
6
+
7
+ xml_accessor :sequence_number, :from => "SequenceNumber", :as => Fixnum
6
8
  xml_accessor :contributor_role, :from => "ContributorRole"
7
9
  xml_accessor :language_code, :from => "LanguageCode"
8
- xml_accessor :sequence_number_within_role, :from => "SequenceNumberWithinRole"
9
- xml_accessor :person_name, :etext, :from => "PersonName"
10
- xml_accessor :person_name_inverted, :etext, :from => "PersonNameInverted"
11
- xml_accessor :titles_before_name, :etext, :from => "TitlesBeforeName"
12
- xml_accessor :names_before_key, :etext, :from => "NamesBeforeKey"
13
- xml_accessor :prefix_to_key, :etext, :from => "PrefixToKey"
14
- xml_accessor :key_names, :etext, :from => "KeyNames"
15
- xml_accessor :names_after_key, :etext, :from => "NamesArterKey"
16
- xml_accessor :suffix_to_key, :etext, :from => "SuffixToKey"
17
- xml_accessor :letters_after_names, :etext, :from => "LettersAfterNames"
18
- xml_accessor :titles_after_names, :etext, :from => "TitlesAfterNames"
19
- xml_accessor :corporate_name, :etext, :from => "CorporateName"
20
- xml_accessor :biographical_note, :etext, :from => "BiographicalNote"
10
+ xml_accessor :sequence_number_within_role, :from => "SequenceNumberWithinRole", :as => Fixnum
11
+ xml_accessor :person_name, :from => "PersonName"
12
+ xml_accessor :person_name_inverted, :from => "PersonNameInverted"
13
+ xml_accessor :titles_before_name, :from => "TitlesBeforeName"
14
+ xml_accessor :names_before_key, :from => "NamesBeforeKey"
15
+ xml_accessor :prefix_to_key, :from => "PrefixToKey"
16
+ xml_accessor :key_names, :from => "KeyNames"
17
+ xml_accessor :names_after_key, :from => "NamesArterKey"
18
+ xml_accessor :suffix_to_key, :from => "SuffixToKey"
19
+ xml_accessor :letters_after_names, :from => "LettersAfterNames"
20
+ xml_accessor :titles_after_names, :from => "TitlesAfterNames"
21
+ xml_accessor :corporate_name, :from => "CorporateName"
22
+ xml_accessor :biographical_note, :from => "BiographicalNote"
21
23
  end
22
24
  end
@@ -4,28 +4,34 @@ module ONIX
4
4
 
5
5
  xml_name "Header"
6
6
 
7
- xml_accessor :from_ean_number, :etext, :from => "FromEANNumber"
8
- xml_accessor :from_san, :etext, :from => "FromSAN"
9
- xml_accessor :sender_identifiers, [ONIX::SenderIdentifier], :from => "SenderIdentifier"
10
- xml_accessor :from_company, :etext, :from => "FromCompany"
11
- xml_accessor :from_person, :etext, :from => "FromPerson"
12
- xml_accessor :from_email, :etext, :from => "FromEmail"
13
- xml_accessor :to_ean_number, :etext, :from => "ToEANNumber"
14
- xml_accessor :to_san, :etext, :from => "ToSAN"
15
- xml_accessor :addressee_identifier, [ONIX::AddresseeIdentifier], :from => "AddresseeIdentifier"
16
- xml_accessor :to_company, :etext, :from => "ToCompany"
17
- xml_accessor :to_person, :etext, :from => "ToPerson"
18
- xml_accessor :message_number, :etext, :from => "MessageNumber"
19
- xml_accessor :message_repeat, :integer, :from => "MessageRepeat"
20
- xml_accessor :sent_date, :yyyymmdd, :from => "SentDate"
21
- xml_accessor :message_note, :etext, :from => "MessageNote"
7
+ xml_accessor :from_ean_number, :from => "FromEANNumber"
8
+ xml_accessor :from_san, :from => "FromSAN"
9
+ xml_accessor :sender_identifiers, :from => "SenderIdentifier", :as => [ONIX::SenderIdentifier]
10
+ xml_accessor :from_company, :from => "FromCompany"
11
+ xml_accessor :from_person, :from => "FromPerson"
12
+ xml_accessor :from_email, :from => "FromEmail"
13
+ xml_accessor :to_ean_number, :from => "ToEANNumber"
14
+ xml_accessor :to_san, :from => "ToSAN"
15
+ xml_accessor :addressee_identifiers, :from => "AddresseeIdentifier", :as => [ONIX::AddresseeIdentifier]
16
+ xml_accessor :to_company, :from => "ToCompany"
17
+ xml_accessor :to_person, :from => "ToPerson"
18
+ xml_accessor :message_number, :from => "MessageNumber"
19
+ xml_accessor :message_repeat, :from => "MessageRepeat", :as => Fixnum
20
+ xml_accessor :sent_date, :from => "SentDate", :as => Date, :to_xml => ONIX::Formatters.yyyymmdd
21
+ xml_accessor :message_note, :from => "MessageNote"
22
22
 
23
23
  # defaults
24
24
  xml_accessor :default_language_of_text, :from => "DefaultLanguageOfText"
25
- xml_accessor :default_price_type_code, :integer, :from => "DefaultPriceTypeCode"
25
+ xml_accessor :default_price_type_code, :from => "DefaultPriceTypeCode", :as => Fixnum, :to_xml => ONIX::Formatters.two_digit
26
26
  xml_accessor :default_currency_code, :from => "DefaultCurrencyCode"
27
- xml_reader :default_linear_unit, :from => "DefaultLinearUnit" # deprecated
28
- xml_reader :default_weight_unit, :from => "DefaultWeightUnit" # deprecated
27
+ xml_reader :default_linear_unit, :from => "DefaultLinearUnit" # deprecated in ONIX spec
28
+ xml_reader :default_weight_unit, :from => "DefaultWeightUnit" # deprecated in ONIX spec
29
29
  xml_accessor :default_class_of_trade, :from => "DefaultClassOfTrade"
30
+
31
+ def initialize
32
+ self.sender_identifiers = []
33
+ self.addressee_identifiers = []
34
+ end
30
35
  end
36
+
31
37
  end
@@ -2,9 +2,11 @@ module ONIX
2
2
  class Imprint
3
3
  include ROXML
4
4
 
5
- xml_accessor :name_code_type, :twodigit, :from => "NameCodeType"
6
- xml_accessor :name_code_type_name, :etext, :from => "NameCodeTypeName"
7
- xml_accessor :name_code_value, :etext, :from => "NameCodeValue"
8
- xml_accessor :imprint_name, :etext, :from => "ImprintName"
5
+ xml_name "Imprint"
6
+
7
+ xml_accessor :name_code_type, :from => "NameCodeType", :as => Fixnum, :to_xml => ONIX::Formatters.two_digit
8
+ xml_accessor :name_code_type_name, :from => "NameCodeTypeName"
9
+ xml_accessor :name_code_value, :from => "NameCodeValue"
10
+ xml_accessor :imprint_name, :from => "ImprintName"
9
11
  end
10
12
  end
@@ -2,13 +2,15 @@ module ONIX
2
2
  class MarketRepresentation
3
3
  include ROXML
4
4
 
5
- xml_accessor :agent_name, :etext, :from => "AgentName"
6
- xml_accessor :agent_role, :twodigit, :from => "AgentRole"
7
- xml_accessor :market_country, :etext, :from => "MarketCountry"
8
- xml_accessor :market_territory, :etext, :from => "MarketTerritory"
9
- xml_accessor :market_country_excluded, :etext, :from => "MarketCountryExcluded"
10
- xml_accessor :market_restriction_detail, :etext, :from => "MarketRestrictionDetail"
11
- xml_accessor :market_publishing_status, :twodigit, :from => "MarketPublishingStatus"
5
+ xml_name "MarketRepresentation"
6
+
7
+ xml_accessor :agent_name, :from => "AgentName"
8
+ xml_accessor :agent_role, :from => "AgentRole", :as => Fixnum, :to_xml => ONIX::Formatters.two_digit
9
+ xml_accessor :market_country, :from => "MarketCountry"
10
+ xml_accessor :market_territory, :from => "MarketTerritory"
11
+ xml_accessor :market_country_excluded, :from => "MarketCountryExcluded"
12
+ xml_accessor :market_restriction_detail, :from => "MarketRestrictionDetail"
13
+ xml_accessor :market_publishing_status, :from => "MarketPublishingStatus", :as => Fixnum, :to_xml => ONIX::Formatters.two_digit
12
14
  end
13
15
  end
14
16
 
@@ -2,8 +2,10 @@ module ONIX
2
2
  class Measure
3
3
  include ROXML
4
4
 
5
- xml_accessor :measure_type_code, :twodigit, :from => "MeasureTypeCode"
6
- xml_accessor :measurement, :decimal, :from => "Measurement"
7
- xml_accessor :measure_unit_code, :etext, :from => "MeasureUnitCode"
5
+ xml_name "Measure"
6
+
7
+ xml_accessor :measure_type_code, :from => "MeasureTypeCode", :as => Fixnum, :to_xml => ONIX::Formatters.two_digit
8
+ xml_accessor :measurement, :from => "Measurement", :as => BigDecimal
9
+ xml_accessor :measure_unit_code, :from => "MeasureUnitCode"
8
10
  end
9
11
  end
@@ -2,10 +2,12 @@ module ONIX
2
2
  class MediaFile
3
3
  include ROXML
4
4
 
5
- xml_accessor :media_file_type_code, :twodigit, :from => "MediaFileTypeCode"
6
- xml_accessor :media_file_format_code, :twodigit, :from => "MediaFileFormatCode"
5
+ xml_name "MediaFile"
6
+
7
+ xml_accessor :media_file_type_code, :from => "MediaFileTypeCode", :as => Fixnum, :to_xml => ONIX::Formatters.two_digit
8
+ xml_accessor :media_file_format_code, :from => "MediaFileFormatCode", :as => Fixnum, :to_xml => ONIX::Formatters.two_digit
7
9
  xml_accessor :image_resolution, :from => "ImageResolution"
8
- xml_accessor :media_file_link_type_code, :twodigit, :from => "MediaFileLinkTypeCode"
10
+ xml_accessor :media_file_link_type_code, :from => "MediaFileLinkTypeCode", :as => Fixnum, :to_xml => ONIX::Formatters.two_digit
9
11
  xml_accessor :media_file_link, :from => "MediaFileLink"
10
12
  end
11
13
  end
@@ -2,11 +2,13 @@ module ONIX
2
2
  class OtherText
3
3
  include ROXML
4
4
 
5
- xml_accessor :text_type_code, :twodigit, :from => "TextTypeCode"
6
- xml_accessor :text_format, :etext, :from => "TextFormat"
7
- xml_accessor :text, :etext, :from => "Text"
8
- xml_accessor :text_link_type, :twodigit, :from => "TextLinkType"
9
- xml_accessor :text_link, :from => "TextLink"
10
- xml_accessor :text_author, :etext, :from => "TextAuthor"
5
+ xml_name "OtherText"
6
+
7
+ xml_accessor :text_type_code, :from => "TextTypeCode", :as => Fixnum, :to_xml => ONIX::Formatters.two_digit
8
+ xml_accessor :text_format, :from => "TextFormat"
9
+ xml_accessor :text, :from => "Text"
10
+ xml_accessor :text_link_type, :from => "TextLinkType", :as => Fixnum, :to_xml => ONIX::Formatters.two_digit
11
+ xml_accessor :text_link, :from => "TextLink"
12
+ xml_accessor :text_author, :from => "TextAuthor"
11
13
  end
12
14
  end
@@ -2,15 +2,17 @@ module ONIX
2
2
  class Price
3
3
  include ROXML
4
4
 
5
- xml_accessor :price_type_code, :twodigit, :from => "PriceTypeCode"
6
- xml_accessor :price_type_qualifier, :from => "PriceTypeQualifier"
5
+ xml_name "Price"
6
+
7
+ xml_accessor :price_type_code, :from => "PriceTypeCode", :as => Fixnum, :to_xml => ONIX::Formatters.two_digit
8
+ xml_accessor :price_type_qualifier, :from => "PriceTypeQualifier", :as => Fixnum, :to_xml => ONIX::Formatters.two_digit
7
9
  xml_accessor :price_type_description, :from => "PriceTypeDescription"
8
- xml_accessor :price_per, :from => "PricePer"
9
- xml_accessor :minimum_order_qty, :from => "MinimumOrderQuantity"
10
+ xml_accessor :price_per, :from => "PricePer", :as => Fixnum, :to_xml => ONIX::Formatters.two_digit
11
+ xml_accessor :minimum_order_qty, :from => "MinimumOrderQuantity", :as => Fixnum
10
12
  xml_accessor :class_of_trade, :from => "ClassOfTrade"
11
13
  xml_accessor :bic_discount_group_code, :from => "BICDiscountGroupCode"
12
- xml_accessor :price_status, :from => "PriceStatus"
13
- xml_accessor :price_amount, :from => "PriceAmount"
14
+ xml_accessor :price_status, :from => "PriceStatus", :as => Fixnum, :to_xml => ONIX::Formatters.two_digit
15
+ xml_accessor :price_amount, :from => "PriceAmount", :as => BigDecimal, :to_xml => ONIX::Formatters.decimal
14
16
  xml_accessor :currency_code, :from => "CurrencyCode"
15
17
  end
16
18
  end
@@ -5,37 +5,52 @@ module ONIX
5
5
  xml_name "Product"
6
6
 
7
7
  xml_accessor :record_reference, :from => "RecordReference"
8
- xml_accessor :notification_type, :twodigit, :from => "NotificationType"
9
- xml_accessor :product_identifiers, [ONIX::ProductIdentifier], :from => "ProductIdentifier"
8
+ xml_accessor :notification_type, :from => "NotificationType", :as => Fixnum, :to_xml => ONIX::Formatters.two_digit
9
+ xml_accessor :product_identifiers, :from => "ProductIdentifier", :as => [ONIX::ProductIdentifier]
10
10
  xml_accessor :product_form, :from => "ProductForm"
11
11
  xml_accessor :series, :from => "Series"
12
- xml_accessor :edition_number, :integer, :from => "EditionNumber"
13
- xml_accessor :titles, [ONIX::Title], :from => "Title"
14
- xml_accessor :contributors, [ONIX::Contributor], :from => "Contributor"
15
- xml_accessor :websites, [ONIX::Website], :from => "Website"
16
- xml_accessor :number_of_pages, :integer, :from => "NumberOfPages"
12
+ xml_accessor :edition_number, :from => "EditionNumber", :as => Fixnum
13
+ xml_accessor :titles, :from => "Title", :as => [ONIX::Title]
14
+ xml_accessor :contributors, :from => "Contributor", :as => [ONIX::Contributor]
15
+ xml_accessor :websites, :from => "Website", :as => [ONIX::Website]
16
+ xml_accessor :number_of_pages, :from => "NumberOfPages", :as => Fixnum
17
17
  xml_accessor :bic_main_subject, :from => "BICMainSubject"
18
- xml_accessor :subjects, [ONIX::Subject], :from => "Subject"
19
- xml_accessor :text, [ONIX::OtherText], :from => "OtherText"
20
- xml_accessor :media_files, [ONIX::MediaFile], :from => "MediaFile"
21
- xml_accessor :imprints, [ONIX::Imprint], :from => "Imprint"
22
- xml_accessor :publishers, [ONIX::Publisher], :from => "Publisher"
23
- xml_accessor :publishing_status, :twodigit, :from => "PublishingStatus"
24
- xml_accessor :publication_date, :yyyymmdd, :from => "PublicationDate"
25
- xml_accessor :year_first_published, :integer, :from => "YearFirstPublished"
26
- xml_accessor :sales_restrictions, [ONIX::SalesRestriction], :from => "SalesRestriction"
27
- xml_accessor :measurements, [ONIX::Measure], :from => "Measure"
28
- xml_accessor :supply_details, [ONIX::SupplyDetail], :from => "SupplyDetail"
29
- xml_accessor :market_representations, [ONIX::MarketRepresentation], :from => "MarketRepresentation"
18
+ xml_accessor :subjects, :from => "Subject", :as => [ONIX::Subject]
19
+ xml_accessor :text, :from => "OtherText", :as => [ONIX::OtherText]
20
+ xml_accessor :media_files, :from => "MediaFile", :as => [ONIX::MediaFile]
21
+ xml_accessor :imprints, :from => "Imprint", :as => [ONIX::Imprint]
22
+ xml_accessor :publishers, :from => "Publisher", :as => [ONIX::Publisher]
23
+ xml_accessor :publishing_status, :from => "PublishingStatus", :as => Fixnum, :to_xml => ONIX::Formatters.two_digit
24
+ xml_accessor :publication_date, :from => "PublicationDate", :as => Date, :to_xml => ONIX::Formatters.yyyymmdd
25
+ xml_accessor :year_first_published, :from => "YearFirstPublished", :as => Fixnum
26
+ xml_accessor :sales_restrictions, :from => "SalesRestriction", :as => [ONIX::SalesRestriction]
27
+ xml_accessor :measurements, :from => "Measure", :as => [ONIX::Measure]
28
+ xml_accessor :supply_details, :from => "SupplyDetail", :as => [ONIX::SupplyDetail]
29
+ xml_accessor :market_representations, :from => "MarketRepresentation", :as => [ONIX::MarketRepresentation]
30
30
 
31
31
  # some deprecated attributes. Read only
32
32
  # - See the measures array for the current way of specifying
33
33
  # various measurements of the product
34
- xml_reader :height, :decimal, :from => "Height"
35
- xml_reader :width, :decimal, :from => "Width"
36
- xml_reader :thickness, :decimal, :from => "Thickness"
37
- xml_reader :weight, :decimal, :from => "Weight"
38
- xml_reader :dimensions, :etext, :from => "Dimensions"
34
+ xml_reader :height, :from => "Height", :as => BigDecimal
35
+ xml_reader :width, :from => "Width", :as => BigDecimal
36
+ xml_reader :thickness, :from => "Thickness", :as => BigDecimal
37
+ xml_reader :weight, :from => "Weight", :as => BigDecimal
38
+ xml_reader :dimensions, :from => "Dimensions"
39
39
 
40
+ def initialize
41
+ self.product_identifiers = []
42
+ self.titles = []
43
+ self.contributors = []
44
+ self.websites = []
45
+ self.subjects = []
46
+ self.text = []
47
+ self.media_files = []
48
+ self.imprints = []
49
+ self.publishers = []
50
+ self.sales_restrictions = []
51
+ self.measurements = []
52
+ self.supply_details = []
53
+ self.market_representations = []
54
+ end
40
55
  end
41
56
  end
@@ -2,7 +2,9 @@ module ONIX
2
2
  class ProductIdentifier
3
3
  include ROXML
4
4
 
5
- xml_accessor :product_id_type, :twodigit, :from => "ProductIDType"
5
+ xml_name "ProductIdentifier"
6
+
7
+ xml_accessor :product_id_type, :from => "ProductIDType", :as => Fixnum, :to_xml => ONIX::Formatters.two_digit
6
8
  xml_accessor :id_value, :from => "IDValue"
7
9
  end
8
10
  end
@@ -2,10 +2,12 @@ module ONIX
2
2
  class Publisher
3
3
  include ROXML
4
4
 
5
- xml_accessor :publishing_role, :twodigit, :from => "PublishingRole"
6
- xml_accessor :name_code_type, :twodigit, :from => "NameCodeType"
7
- xml_accessor :name_code_type_name, :etext, :from => "NameCodeTypeName"
8
- xml_accessor :name_code_type_value, :etext, :from => "NameCodeTypeValue"
9
- xml_accessor :publisher_name, :etext, :from => "PublisherName"
5
+ xml_name "Publisher"
6
+
7
+ xml_accessor :publishing_role, :from => "PublishingRole", :as => Fixnum, :to_xml => ONIX::Formatters.two_digit
8
+ xml_accessor :name_code_type, :from => "NameCodeType", :as => Fixnum, :to_xml => ONIX::Formatters.two_digit
9
+ xml_accessor :name_code_type_name, :from => "NameCodeTypeName"
10
+ xml_accessor :name_code_type_value, :from => "NameCodeTypeValue"
11
+ xml_accessor :publisher_name, :from => "PublisherName"
10
12
  end
11
13
  end
@@ -52,7 +52,7 @@ module ONIX
52
52
  #
53
53
  class Reader
54
54
 
55
- attr_reader :header, :version, :xml_lang, :xml_version, :encoding
55
+ attr_reader :header, :version, :xml_lang, :xml_version, :encoding, :queue
56
56
 
57
57
  # Create a new ONIX::Reader object
58
58
  #
@@ -105,24 +105,67 @@ module ONIX
105
105
  # user uses the each() method.
106
106
  #
107
107
  def read_input
108
- while @reader.read == 1
108
+ while @reader.read
109
109
  @xml_lang = @reader.xml_lang if @xml_lang.nil?
110
110
  @xml_version = @reader.xml_version.to_f if @xml_version.nil?
111
- @encoding = @reader.encoding if @encoding.nil?
112
- if @reader.node_type == 10
111
+ @encoding = encoding_const_to_name(@reader.encoding) if @encoding.nil?
112
+ if @reader.node_type == LibXML::XML::Reader::TYPE_DOCUMENT_TYPE
113
113
  uri = @reader.expand.to_s
114
114
  m, major, minor, rev = *uri.match(/.+(\d)\.(\d)\/(\d*).*/)
115
115
  @version = [major.to_i, minor.to_i, rev.to_i]
116
- elsif @reader.name == "Header" && @reader.node_type == 1
117
- @header = ONIX::Header.parse(@reader.expand.to_s)
116
+ elsif @reader.name == "Header" && @reader.node_type == LibXML::XML::Reader::TYPE_ELEMENT
117
+ @header = ONIX::Header.from_xml(@reader.expand.to_s)
118
118
  @reader.next_sibling
119
- elsif @reader.name == "Product" && @reader.node_type == 1
119
+ elsif @reader.name == "Product" && @reader.node_type == LibXML::XML::Reader::TYPE_ELEMENT
120
120
  node = @reader.expand
121
- @queue.push @product_klass.parse(node.to_s)
121
+ @queue.push @product_klass.from_xml(node.to_s)
122
122
  @reader.next_sibling
123
123
  end
124
124
  end
125
125
  @queue.push nil
126
126
  end
127
+
128
+ def encoding_const_to_name(const)
129
+ case const
130
+ when LibXML::XML::Encoding::UTF_8
131
+ "utf-8"
132
+ when LibXML::XML::Encoding::UTF_16LE
133
+ "utf-16le"
134
+ when LibXML::XML::Encoding::UTF_16BE
135
+ "utf-16be"
136
+ when LibXML::XML::Encoding::UCS_4LE
137
+ "ucs-4le"
138
+ when LibXML::XML::Encoding::UCS_4BE
139
+ "ucs-4be"
140
+ when LibXML::XML::Encoding::UCS_2
141
+ "ucs-2"
142
+ when LibXML::XML::Encoding::ISO_8859_1
143
+ "iso-8859-1"
144
+ when LibXML::XML::Encoding::ISO_8859_2
145
+ "iso-8859-2"
146
+ when LibXML::XML::Encoding::ISO_8859_3
147
+ "iso-8859-3"
148
+ when LibXML::XML::Encoding::ISO_8859_4
149
+ "iso-8859-4"
150
+ when LibXML::XML::Encoding::ISO_8859_5
151
+ "iso-8859-5"
152
+ when LibXML::XML::Encoding::ISO_8859_6
153
+ "iso-8859-6"
154
+ when LibXML::XML::Encoding::ISO_8859_7
155
+ "iso-8859-7"
156
+ when LibXML::XML::Encoding::ISO_8859_8
157
+ "iso-8859-8"
158
+ when LibXML::XML::Encoding::ISO_8859_9
159
+ "iso-8859-9"
160
+ when LibXML::XML::Encoding::ISO_2022_JP
161
+ "iso-2022-jp"
162
+ when LibXML::XML::Encoding::SHIF_JIS
163
+ "shift-jis"
164
+ when LibXML::XML::Encoding::EUC_JP
165
+ "euc-jp"
166
+ when LibXML::XML::Encoding::ASCII
167
+ "ascii"
168
+ end
169
+ end
127
170
  end
128
171
  end