onix2 1.0.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.
- checksums.yaml +7 -0
- data/CHANGELOG +209 -0
- data/README.markdown +69 -0
- data/TODO +14 -0
- data/dtd/2.1r3/iso-amsa.ent +173 -0
- data/dtd/2.1r3/iso-amsb.ent +146 -0
- data/dtd/2.1r3/iso-amsc.ent +49 -0
- data/dtd/2.1r3/iso-amsn.ent +117 -0
- data/dtd/2.1r3/iso-amso.ent +77 -0
- data/dtd/2.1r3/iso-amsr.ent +205 -0
- data/dtd/2.1r3/iso-box.ent +67 -0
- data/dtd/2.1r3/iso-cyr1.ent +94 -0
- data/dtd/2.1r3/iso-cyr2.ent +53 -0
- data/dtd/2.1r3/iso-dia.ent +41 -0
- data/dtd/2.1r3/iso-grk3.ent +70 -0
- data/dtd/2.1r3/iso-lat1.ent +89 -0
- data/dtd/2.1r3/iso-lat2.ent +148 -0
- data/dtd/2.1r3/iso-mfrk.ent +79 -0
- data/dtd/2.1r3/iso-mopf.ent +53 -0
- data/dtd/2.1r3/iso-mscr.ent +79 -0
- data/dtd/2.1r3/iso-num.ent +103 -0
- data/dtd/2.1r3/iso-num.old.ent +103 -0
- data/dtd/2.1r3/iso-pub.ent +110 -0
- data/dtd/2.1r3/iso-tech.ent +183 -0
- data/dtd/2.1r3/onix-international.dtd +1012 -0
- data/dtd/2.1r3/onix-xhtml.elt +672 -0
- data/dtd/2.1r3/reference.elt +4758 -0
- data/dtd/2.1r3/xhtml-special.ent +79 -0
- data/dtd/2.1r3/xhtml-symbol.ent +242 -0
- data/lib/onix2.rb +85 -0
- data/lib/onix2/addressee_identifier.rb +29 -0
- data/lib/onix2/apa_product.rb +785 -0
- data/lib/onix2/audience_range.rb +37 -0
- data/lib/onix2/code_list_extractor.rb +69 -0
- data/lib/onix2/contributor.rb +55 -0
- data/lib/onix2/discount_coded.rb +29 -0
- data/lib/onix2/header.rb +68 -0
- data/lib/onix2/imprint.rb +31 -0
- data/lib/onix2/language.rb +29 -0
- data/lib/onix2/lists.rb +134 -0
- data/lib/onix2/market_representation.rb +38 -0
- data/lib/onix2/measure.rb +29 -0
- data/lib/onix2/media_file.rb +33 -0
- data/lib/onix2/other_text.rb +35 -0
- data/lib/onix2/price.rb +47 -0
- data/lib/onix2/product.rb +97 -0
- data/lib/onix2/product_identifier.rb +27 -0
- data/lib/onix2/publisher.rb +33 -0
- data/lib/onix2/reader.rb +157 -0
- data/lib/onix2/sales_restriction.rb +25 -0
- data/lib/onix2/sales_rights.rb +28 -0
- data/lib/onix2/sender_identifier.rb +29 -0
- data/lib/onix2/series.rb +28 -0
- data/lib/onix2/series_identifier.rb +27 -0
- data/lib/onix2/simple_product.rb +47 -0
- data/lib/onix2/stock.rb +29 -0
- data/lib/onix2/subject.rb +33 -0
- data/lib/onix2/supply_detail.rb +53 -0
- data/lib/onix2/title.rb +33 -0
- data/lib/onix2/version.rb +3 -0
- data/lib/onix2/website.rb +29 -0
- data/lib/onix2/writer.rb +86 -0
- data/spec/addressee_identifier_spec.rb +33 -0
- data/spec/apa_product_spec.rb +116 -0
- data/spec/audience_range_spec.rb +44 -0
- data/spec/contributor_spec.rb +38 -0
- data/spec/discount_coded_spec.rb +34 -0
- data/spec/header_spec.rb +153 -0
- data/spec/imprint_spec.rb +31 -0
- data/spec/language_spec.rb +38 -0
- data/spec/lists_spec.rb +33 -0
- data/spec/market_representation_spec.rb +33 -0
- data/spec/measure_spec.rb +38 -0
- data/spec/media_file_spec.rb +38 -0
- data/spec/other_text_spec.rb +33 -0
- data/spec/price_spec.rb +52 -0
- data/spec/product_identifier_spec.rb +34 -0
- data/spec/product_spec.rb +102 -0
- data/spec/publisher_spec.rb +33 -0
- data/spec/reader_spec.rb +155 -0
- data/spec/sales_restriction_spec.rb +27 -0
- data/spec/sender_identifier.rb +33 -0
- data/spec/series_identifier_spec.rb +33 -0
- data/spec/series_spec.rb +47 -0
- data/spec/spec_helper.rb +15 -0
- data/spec/stock_spec.rb +39 -0
- data/spec/subject_spec.rb +34 -0
- data/spec/supply_detail_spec.rb +97 -0
- data/spec/title_spec.rb +38 -0
- data/spec/website_spec.rb +33 -0
- data/spec/writer_spec.rb +78 -0
- data/support/codes/001.tsv +10 -0
- data/support/codes/002.tsv +5 -0
- data/support/codes/003.tsv +7 -0
- data/support/codes/005.tsv +13 -0
- data/support/codes/006.tsv +76 -0
- data/support/codes/007.tsv +123 -0
- data/support/codes/008.tsv +7 -0
- data/support/codes/009.tsv +7 -0
- data/support/codes/010.tsv +34 -0
- data/support/codes/011.tsv +11 -0
- data/support/codes/012.tsv +11 -0
- data/support/codes/013.tsv +7 -0
- data/support/codes/014.tsv +4 -0
- data/support/codes/015.tsv +13 -0
- data/support/codes/016.tsv +6 -0
- data/support/codes/017.tsv +90 -0
- data/support/codes/018.tsv +3 -0
- data/support/codes/019.tsv +7 -0
- data/support/codes/020.tsv +0 -0
- data/support/codes/021.tsv +31 -0
- data/support/codes/022.tsv +9 -0
- data/support/codes/023.tsv +9 -0
- data/support/codes/024.tsv +11 -0
- data/support/codes/025.tsv +29 -0
- data/support/codes/026.tsv +75 -0
- data/support/codes/027.tsv +75 -0
- data/support/codes/028.tsv +8 -0
- data/support/codes/029.tsv +16 -0
- data/support/codes/030.tsv +15 -0
- data/support/codes/031.tsv +3 -0
- data/support/codes/032.tsv +2 -0
- data/support/codes/033.tsv +36 -0
- data/support/codes/034.tsv +14 -0
- data/support/codes/035.tsv +6 -0
- data/support/codes/036.tsv +3 -0
- data/support/codes/037.tsv +6 -0
- data/support/codes/038.tsv +36 -0
- data/support/codes/039.tsv +8 -0
- data/support/codes/040.tsv +6 -0
- data/support/codes/041.tsv +6 -0
- data/support/codes/042.tsv +16 -0
- data/support/codes/043.tsv +4 -0
- data/support/codes/044.tsv +13 -0
- data/support/codes/045.tsv +12 -0
- data/support/codes/046.tsv +3 -0
- data/support/codes/047.tsv +4 -0
- data/support/codes/048.tsv +11 -0
- data/support/codes/049.tsv +84 -0
- data/support/codes/050.tsv +8 -0
- data/support/codes/051.tsv +27 -0
- data/support/codes/052.tsv +1 -0
- data/support/codes/053.tsv +3 -0
- data/support/codes/054.tsv +23 -0
- data/support/codes/055.tsv +13 -0
- data/support/codes/056.tsv +2 -0
- data/support/codes/057.tsv +5 -0
- data/support/codes/058.tsv +21 -0
- data/support/codes/059.tsv +4 -0
- data/support/codes/060.tsv +2 -0
- data/support/codes/061.tsv +3 -0
- data/support/codes/062.tsv +5 -0
- data/support/codes/063.tsv +0 -0
- data/support/codes/064.tsv +13 -0
- data/support/codes/065.tsv +25 -0
- data/support/codes/066.tsv +4 -0
- data/support/codes/067.tsv +2 -0
- data/support/codes/068.tsv +15 -0
- data/support/codes/069.tsv +4 -0
- data/support/codes/070.tsv +2 -0
- data/support/codes/071.tsv +9 -0
- data/support/codes/072.tsv +7 -0
- data/support/codes/073.tsv +36 -0
- data/support/codes/074.tsv +489 -0
- data/support/codes/075.tsv +2 -0
- data/support/codes/076.tsv +12 -0
- data/support/codes/077.tsv +19 -0
- data/support/codes/078.tsv +148 -0
- data/support/codes/079.tsv +17 -0
- data/support/codes/080.tsv +19 -0
- data/support/codes/081.tsv +11 -0
- data/support/codes/082.tsv +17 -0
- data/support/codes/083.tsv +68 -0
- data/support/codes/084.tsv +10 -0
- data/support/codes/085.tsv +23 -0
- data/support/codes/086.tsv +5 -0
- data/support/codes/087.tsv +6 -0
- data/support/codes/088.tsv +0 -0
- data/support/codes/089.tsv +1 -0
- data/support/codes/090.tsv +11 -0
- data/support/codes/091.tsv +248 -0
- data/support/codes/092.tsv +7 -0
- data/support/codes/093.tsv +13 -0
- data/support/codes/094.tsv +3 -0
- data/support/codes/095.tsv +3 -0
- data/support/codes/096.tsv +185 -0
- data/support/codes/097.tsv +1 -0
- data/support/codes/098.tsv +21 -0
- data/support/codes/099.tsv +24 -0
- data/support/codes/100.tsv +4 -0
- data/support/codes/101.tsv +2 -0
- data/support/codes/102.tsv +3 -0
- data/support/codes/121.tsv +127 -0
- data/support/codes/138.tsv +6 -0
- data/support/codes/139.tsv +70 -0
- data/support/codes/140.tsv +7 -0
- data/support/codes/141.tsv +10 -0
- data/support/codes/142.tsv +12 -0
- data/support/codes/143.tsv +7 -0
- data/support/codes/144.tsv +4 -0
- data/support/codes/145.tsv +5 -0
- data/support/codes/146.tsv +3 -0
- data/support/codes/147.tsv +7 -0
- data/support/codes/148.tsv +3 -0
- data/support/codes/149.tsv +4 -0
- data/support/codes/150.tsv +124 -0
- data/support/codes/151.tsv +7 -0
- data/support/codes/152.tsv +2 -0
- data/support/codes/153.tsv +14 -0
- data/support/codes/154.tsv +9 -0
- data/support/codes/155.tsv +5 -0
- data/support/codes/156.tsv +4 -0
- data/support/codes/157.tsv +4 -0
- data/support/codes/158.tsv +24 -0
- data/support/codes/159.tsv +6 -0
- data/support/codes/160.tsv +0 -0
- data/support/codes/161.tsv +3 -0
- data/support/codes/162.tsv +3 -0
- data/support/codes/163.tsv +7 -0
- data/support/codes/164.tsv +2 -0
- data/support/codes/165.tsv +2 -0
- data/support/codes/166.tsv +2 -0
- data/support/codes/167.tsv +3 -0
- data/support/codes/168.tsv +2 -0
- data/support/codes/169.tsv +3 -0
- data/support/codes/170.tsv +0 -0
- data/support/codes/171.tsv +2 -0
- data/support/codes/172.tsv +1 -0
- data/support/codes/173.tsv +2 -0
- data/support/codes/174.tsv +2 -0
- data/support/codes/175.tsv +175 -0
- data/support/codes/176.tsv +12 -0
- data/support/codes/177.tsv +2 -0
- data/support/codes/178.tsv +17 -0
- data/support/entities.txt +1499 -0
- data/support/extract.rb +25 -0
- data/support/switch-onix-2.1-short-to-reference.xsl +24 -0
- data/support/switch-onix-tagnames-1.1.xsl +25 -0
- data/support/switch-onix-tagnames-2.0.xsl +37 -0
- metadata +440 -0
@@ -0,0 +1,37 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
module ONIX2
|
4
|
+
class AudienceRange
|
5
|
+
include Virtus.model
|
6
|
+
|
7
|
+
attribute :audience_range_qualifier, Integer
|
8
|
+
attribute :audience_range_precisions, Array[Integer]
|
9
|
+
attribute :audience_range_values, Array[Integer]
|
10
|
+
|
11
|
+
# TODO: element AudienceRange: validity error :
|
12
|
+
# Element AudienceRange content does not follow the DTD, expecting
|
13
|
+
# (AudienceRangeQualifier , AudienceRangePrecision , AudienceRangeValue ,
|
14
|
+
# (AudienceRangePrecision , AudienceRangeValue)?),
|
15
|
+
# got
|
16
|
+
# (AudienceRangeQualifier AudienceRangePrecision AudienceRangePrecision
|
17
|
+
# AudienceRangeValue AudienceRangeValue )
|
18
|
+
|
19
|
+
def to_xml
|
20
|
+
AudienceRangeRepresenter.new(self).to_xml
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.from_xml(data)
|
24
|
+
AudienceRangeRepresenter.new(self.new).from_xml(data)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
class AudienceRangeRepresenter < Representable::Decorator
|
29
|
+
include Representable::XML
|
30
|
+
|
31
|
+
self.representation_wrap = :AudienceRange
|
32
|
+
|
33
|
+
property :audience_range_qualifier, as: "AudienceRangeQualifier", render_filter: ::ONIX2::Formatters::TWO_DIGITS
|
34
|
+
collection :audience_range_precisions, as: "AudienceRangePrecision", render_filter: ::ONIX2::Formatters::TWO_DIGITS
|
35
|
+
collection :audience_range_values, as: "AudienceRangeValue", render_filter: ::ONIX2::Formatters::TWO_DIGITS
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
module ONIX2
|
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
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
module ONIX2
|
4
|
+
class Contributor
|
5
|
+
include Virtus.model
|
6
|
+
|
7
|
+
attribute :sequence_number, Integer
|
8
|
+
attribute :contributor_role
|
9
|
+
attribute :language_code
|
10
|
+
attribute :sequence_number_within_role, Integer
|
11
|
+
attribute :person_name
|
12
|
+
attribute :person_name_inverted
|
13
|
+
attribute :titles_before_names
|
14
|
+
attribute :names_before_key
|
15
|
+
attribute :prefix_to_key
|
16
|
+
attribute :key_names
|
17
|
+
attribute :names_after_key
|
18
|
+
attribute :suffix_to_key
|
19
|
+
attribute :letters_after_names
|
20
|
+
attribute :titles_after_names
|
21
|
+
attribute :corporate_name
|
22
|
+
attribute :biographical_note
|
23
|
+
|
24
|
+
def to_xml
|
25
|
+
ContributorRepresenter.new(self).to_xml
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.from_xml(data)
|
29
|
+
ContributorRepresenter.new(self.new).from_xml(data)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
class ContributorRepresenter < Representable::Decorator
|
34
|
+
include Representable::XML
|
35
|
+
|
36
|
+
self.representation_wrap = :Contributor
|
37
|
+
|
38
|
+
property :sequence_number, as: "SequenceNumber"
|
39
|
+
property :contributor_role, as: "ContributorRole"
|
40
|
+
property :language_code, as: "LanguageCode"
|
41
|
+
property :sequence_number_within_role, as: "SequenceNumberWithinRole"
|
42
|
+
property :person_name, as: "PersonName"
|
43
|
+
property :person_name_inverted, as: "PersonNameInverted"
|
44
|
+
property :titles_before_names, as: "TitlesBeforeNames"
|
45
|
+
property :names_before_key, as: "NamesBeforeKey"
|
46
|
+
property :prefix_to_key, as: "PrefixToKey"
|
47
|
+
property :key_names, as: "KeyNames"
|
48
|
+
property :names_after_key, as: "NamesArterKey"
|
49
|
+
property :suffix_to_key, as: "SuffixToKey"
|
50
|
+
property :letters_after_names, as: "LettersAfterNames"
|
51
|
+
property :titles_after_names, as: "TitlesAfterNames"
|
52
|
+
property :corporate_name, as: "CorporateName"
|
53
|
+
property :biographical_note, as: "BiographicalNote"
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
module ONIX2
|
4
|
+
class DiscountCoded
|
5
|
+
include Virtus.model
|
6
|
+
|
7
|
+
attribute :discount_code_type, Integer
|
8
|
+
attribute :discount_code_type_name
|
9
|
+
attribute :discount_code
|
10
|
+
|
11
|
+
def to_xml
|
12
|
+
DiscountCodedRepresenter.new(self).to_xml
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.from_xml(data)
|
16
|
+
DiscountCodedRepresenter.new(self.new).from_xml(data)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
class DiscountCodedRepresenter < Representable::Decorator
|
21
|
+
include Representable::XML
|
22
|
+
|
23
|
+
self.representation_wrap = :DiscountCoded
|
24
|
+
|
25
|
+
property :discount_code_type, as: "DiscountCodeType", render_filter: ::ONIX2::Formatters::TWO_DIGITS
|
26
|
+
property :discount_code_type_name, as: "DiscountCodeTypeName"
|
27
|
+
property :discount_code, as: "DiscountCode"
|
28
|
+
end
|
29
|
+
end
|
data/lib/onix2/header.rb
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
module ONIX2
|
4
|
+
class Header
|
5
|
+
include Virtus.model
|
6
|
+
|
7
|
+
attribute :from_ean_number
|
8
|
+
attribute :from_san
|
9
|
+
attribute :sender_identifiers, Array[ONIX2::SenderIdentifier]
|
10
|
+
attribute :from_company
|
11
|
+
attribute :from_person
|
12
|
+
attribute :from_email
|
13
|
+
attribute :to_ean_number
|
14
|
+
attribute :to_san
|
15
|
+
attribute :addressee_identifiers, Array[ONIX2::AddresseeIdentifier]
|
16
|
+
attribute :to_company
|
17
|
+
attribute :to_person
|
18
|
+
attribute :message_number
|
19
|
+
attribute :message_repeat, Integer
|
20
|
+
attribute :sent_date
|
21
|
+
attribute :message_note
|
22
|
+
|
23
|
+
# defaults
|
24
|
+
attribute :default_language_of_text
|
25
|
+
attribute :default_price_type_code, Integer
|
26
|
+
attribute :default_currency_code
|
27
|
+
attribute :default_linear_unit # deprecated in ONIX spec
|
28
|
+
attribute :default_weight_unit # deprecated in ONIX spec
|
29
|
+
attribute :default_class_of_trade
|
30
|
+
|
31
|
+
def to_xml
|
32
|
+
HeaderRepresenter.new(self).to_xml
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.from_xml(data)
|
36
|
+
HeaderRepresenter.new(self.new).from_xml(data)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
class HeaderRepresenter < Representable::Decorator
|
41
|
+
include Representable::XML
|
42
|
+
|
43
|
+
self.representation_wrap = :Header
|
44
|
+
|
45
|
+
property :from_ean_number, as: "FromEANNumber"
|
46
|
+
property :from_san, as: "FromSAN"
|
47
|
+
collection :sender_identifiers, as: "SenderIdentifier", extend: ONIX2::SenderIdentifierRepresenter, class: ONIX2::SenderIdentifier
|
48
|
+
property :from_company, as: "FromCompany"
|
49
|
+
property :from_person, as: "FromPerson"
|
50
|
+
property :from_email, as: "FromEmail"
|
51
|
+
property :to_ean_number, as: "ToEANNumber"
|
52
|
+
property :to_san, as: "ToSAN"
|
53
|
+
collection :addressee_identifiers, as: "AddresseeIdentifier", extend: ONIX2::AddresseeIdentifierRepresenter, class: ONIX2::AddresseeIdentifier
|
54
|
+
property :to_company, as: "ToCompany"
|
55
|
+
property :to_person, as: "ToPerson"
|
56
|
+
property :message_number, as: "MessageNumber"
|
57
|
+
property :message_repeat, as: "MessageRepeat"
|
58
|
+
property :sent_date, as: "SentDate", render_filter: ::ONIX2::Formatters::YYYYMMDD, parse_filter: ->(value, *context) { Date.parse(value) rescue nil }
|
59
|
+
property :message_note, as: "MessageNote"
|
60
|
+
property :default_language_of_text, as: "DefaultLanguageOfText"
|
61
|
+
property :default_price_type_code, as: "DefaultPriceTypeCode", render_filter: ::ONIX2::Formatters::TWO_DIGITS
|
62
|
+
property :default_currency_code, as: "DefaultCurrencyCode"
|
63
|
+
property :default_linear_unit, as: "DefaultLinearUnit"
|
64
|
+
property :default_weight_unit, as: "DefaultWeightUnit"
|
65
|
+
property :default_class_of_trade, as: "DefaultClassOfTrade"
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
module ONIX2
|
4
|
+
class Imprint
|
5
|
+
include Virtus.model
|
6
|
+
|
7
|
+
attribute :name_code_type, Integer
|
8
|
+
attribute :name_code_type_name
|
9
|
+
attribute :name_code_value
|
10
|
+
attribute :imprint_name
|
11
|
+
|
12
|
+
def to_xml
|
13
|
+
ImprintRepresenter.new(self).to_xml
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.from_xml(data)
|
17
|
+
ImprintRepresenter.new(self.new).from_xml(data)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
class ImprintRepresenter < Representable::Decorator
|
22
|
+
include Representable::XML
|
23
|
+
|
24
|
+
self.representation_wrap = :Imprint
|
25
|
+
|
26
|
+
property :name_code_type, as: "NameCodeType", render_filter: ::ONIX2::Formatters::TWO_DIGITS
|
27
|
+
property :name_code_type_name, as: "NameCodeTypeName"
|
28
|
+
property :name_code_value, as: "NameCodeValue"
|
29
|
+
property :imprint_name, as: "ImprintName"
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
module ONIX2
|
4
|
+
class Language
|
5
|
+
include Virtus.model
|
6
|
+
|
7
|
+
attribute :language_role, Integer
|
8
|
+
attribute :language_code
|
9
|
+
attribute :country_code
|
10
|
+
|
11
|
+
def to_xml
|
12
|
+
LanguageRepresenter.new(self).to_xml
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.from_xml(data)
|
16
|
+
LanguageRepresenter.new(self.new).from_xml(data)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
class LanguageRepresenter < Representable::Decorator
|
21
|
+
include Representable::XML
|
22
|
+
|
23
|
+
self.representation_wrap = :Language
|
24
|
+
|
25
|
+
property :language_role, as: "LanguageRole", render_filter: ::ONIX2::Formatters::TWO_DIGITS
|
26
|
+
property :language_code, as: "LanguageCode"
|
27
|
+
property :country_code, as: "CountryCode"
|
28
|
+
end
|
29
|
+
end
|
data/lib/onix2/lists.rb
ADDED
@@ -0,0 +1,134 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
module ONIX2
|
4
|
+
|
5
|
+
# Builds hashes for all code lists in the ONIX spec.
|
6
|
+
#
|
7
|
+
# Use like so:
|
8
|
+
#
|
9
|
+
# ONIX2::Lists.list(7)
|
10
|
+
# => { "BB" => "Hardback", ... }
|
11
|
+
#
|
12
|
+
# There are also some constants for commonly used lists:
|
13
|
+
#
|
14
|
+
# ONIX2::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
|
+
# ONIX2::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
|
+
# ONIX2::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 = ONIX2::Lists.audience_code
|
124
|
+
CONTRIBUTOR_ROLE = ONIX2::Lists.contributor_role
|
125
|
+
COUNTRY_CODE = ONIX2::Lists.country_code
|
126
|
+
LANGUAGE_CODE = ONIX2::Lists.language_code
|
127
|
+
LANGUAGE_ROLE = ONIX2::Lists.language_role
|
128
|
+
NOTIFICATION_TYPE = ONIX2::Lists.notification_type
|
129
|
+
PRODUCT_AVAILABILITY = ONIX2::Lists.product_availability
|
130
|
+
PRODUCT_FORM = ONIX2::Lists.product_form
|
131
|
+
PRODUCT_FORM_DETAIL = ONIX2::Lists.product_form_detail
|
132
|
+
|
133
|
+
end
|
134
|
+
end
|