onix2 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- 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,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
module ONIX2
|
4
|
+
class SalesRestriction
|
5
|
+
include Virtus.model
|
6
|
+
|
7
|
+
attribute :sales_restriction_type, Integer
|
8
|
+
|
9
|
+
def to_xml
|
10
|
+
SalesRestrictionRepresenter.new(self).to_xml
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.from_xml(data)
|
14
|
+
SalesRestrictionRepresenter.new(self.new).from_xml(data)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
class SalesRestrictionRepresenter < Representable::Decorator
|
19
|
+
include Representable::XML
|
20
|
+
|
21
|
+
self.representation_wrap = :SalesRestriction
|
22
|
+
|
23
|
+
property :sales_restriction_type, as: "SalesRestrictionType", render_filter: ::ONIX2::Formatters::TWO_DIGITS
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module ONIX2
|
2
|
+
class SalesRights
|
3
|
+
include Virtus.model
|
4
|
+
|
5
|
+
attribute :sales_rights_type
|
6
|
+
attribute :rights_country
|
7
|
+
attribute :rights_territory
|
8
|
+
|
9
|
+
def to_xml
|
10
|
+
SalesRightsRepresenter.new(self).to_xml
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.from_xml(data)
|
14
|
+
SalesRightsRepresenter.new(self.new).from_xml(data)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
class SalesRightsRepresenter < Representable::Decorator
|
19
|
+
include Representable::XML
|
20
|
+
|
21
|
+
self.representation_wrap = :SalesRights
|
22
|
+
|
23
|
+
property :sales_rights_type, as: "SalesRightsType"
|
24
|
+
property :rights_country, as: "RightsCountry"
|
25
|
+
property :rights_territory, as: "RightsTerritory"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
module ONIX2
|
4
|
+
class SenderIdentifier
|
5
|
+
include Virtus.model
|
6
|
+
|
7
|
+
attribute :sender_id_type, Integer
|
8
|
+
attribute :id_type_name
|
9
|
+
attribute :id_value
|
10
|
+
|
11
|
+
def to_xml
|
12
|
+
SenderIdentifierRepresenter.new(self).to_xml
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.from_xml(data)
|
16
|
+
SenderIdentifierRepresenter.new(self.new).from_xml(data)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
class SenderIdentifierRepresenter < Representable::Decorator
|
21
|
+
include Representable::XML
|
22
|
+
|
23
|
+
self.representation_wrap = :SenderIdentifier
|
24
|
+
|
25
|
+
property :sender_id_type, as: "SenderIDType", render_filter: ::ONIX2::Formatters::TWO_DIGITS
|
26
|
+
property :id_type_name, as: "IDTypeName"
|
27
|
+
property :id_value, as: "IDValue"
|
28
|
+
end
|
29
|
+
end
|
data/lib/onix2/series.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
module ONIX2
|
4
|
+
class Series
|
5
|
+
include Virtus.model
|
6
|
+
|
7
|
+
attribute :series_identifiers, Array[ONIX2::SeriesIdentifier]
|
8
|
+
attribute :title_of_series
|
9
|
+
|
10
|
+
def to_xml
|
11
|
+
SeriesRepresenter.new(self).to_xml
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.from_xml(data)
|
15
|
+
SeriesRepresenter.new(self.new).from_xml(data)
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
class SeriesRepresenter < Representable::Decorator
|
21
|
+
include Representable::XML
|
22
|
+
|
23
|
+
self.representation_wrap = :Series
|
24
|
+
|
25
|
+
collection :series_identifiers, as: "SeriesIdentifier", extend: ONIX2::SeriesIdentifierRepresenter, class: ONIX2::SeriesIdentifier
|
26
|
+
property :title_of_series, as: "TitleOfSeries"
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
module ONIX2
|
4
|
+
class SeriesIdentifier
|
5
|
+
include Virtus.model
|
6
|
+
|
7
|
+
attribute :series_id_type, Integer
|
8
|
+
attribute :id_value
|
9
|
+
|
10
|
+
def to_xml
|
11
|
+
SeriesIdentifierRepresenter.new(self).to_xml
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.from_xml(data)
|
15
|
+
SeriesIdentifierRepresenter.new(self.new).from_xml(data)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
class SeriesIdentifierRepresenter < Representable::Decorator
|
20
|
+
include Representable::XML
|
21
|
+
|
22
|
+
self.representation_wrap = :SeriesIdentifier
|
23
|
+
|
24
|
+
property :series_id_type, as: "SeriesIDType", render_filter: ::ONIX2::Formatters::TWO_DIGITS
|
25
|
+
property :id_value, as: "IDValue"
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
require 'forwardable'
|
4
|
+
|
5
|
+
module ONIX2
|
6
|
+
# super class for some simplified ONIX2::Product wrappers
|
7
|
+
class SimpleProduct
|
8
|
+
|
9
|
+
def initialize(product = nil)
|
10
|
+
@product = product || ::ONIX2::Product.new
|
11
|
+
end
|
12
|
+
|
13
|
+
class << self
|
14
|
+
|
15
|
+
include Forwardable
|
16
|
+
|
17
|
+
def from_xml(xml)
|
18
|
+
self.new(::ONIX2::Product.from_xml(xml))
|
19
|
+
end
|
20
|
+
|
21
|
+
def parse_file(filename)
|
22
|
+
self.new(::ONIX2::Product.parse(File.read(filename)))
|
23
|
+
end
|
24
|
+
|
25
|
+
def parse(xml)
|
26
|
+
self.new(::ONIX2::Product.parse(xml))
|
27
|
+
end
|
28
|
+
|
29
|
+
protected
|
30
|
+
|
31
|
+
def delegate(*args)
|
32
|
+
def_delegators :@product, *args
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def product
|
37
|
+
@product
|
38
|
+
end
|
39
|
+
|
40
|
+
def to_xml
|
41
|
+
product.to_xml
|
42
|
+
end
|
43
|
+
|
44
|
+
# TODO: add method missing magic to proxy through to the underlying product?
|
45
|
+
|
46
|
+
end
|
47
|
+
end
|
data/lib/onix2/stock.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
module ONIX2
|
4
|
+
class Stock
|
5
|
+
include Virtus.model
|
6
|
+
|
7
|
+
# NOTE: these *should* be numeric fields according to the spec,
|
8
|
+
# but heaps of ONIX files in the wild use text
|
9
|
+
attribute :on_hand
|
10
|
+
attribute :on_order
|
11
|
+
|
12
|
+
def to_xml
|
13
|
+
StockRepresenter.new(self).to_xml
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.from_xml(data)
|
17
|
+
StockRepresenter.new(self.new).from_xml(data)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
class StockRepresenter < Representable::Decorator
|
22
|
+
include Representable::XML
|
23
|
+
|
24
|
+
self.representation_wrap = :Stock
|
25
|
+
|
26
|
+
property :on_hand, as: "OnHand"
|
27
|
+
property :on_order, as: "OnOrder"
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
module ONIX2
|
4
|
+
class Subject
|
5
|
+
include Virtus.model
|
6
|
+
|
7
|
+
attribute :subject_scheme_id, Integer
|
8
|
+
attribute :subject_scheme_name
|
9
|
+
attribute :subject_scheme_version
|
10
|
+
attribute :subject_code
|
11
|
+
attribute :subject_heading_text
|
12
|
+
|
13
|
+
def to_xml
|
14
|
+
SubjectRepresenter.new(self).to_xml
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.from_xml(data)
|
18
|
+
SubjectRepresenter.new(self.new).from_xml(data)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
class SubjectRepresenter < Representable::Decorator
|
23
|
+
include Representable::XML
|
24
|
+
|
25
|
+
self.representation_wrap = :Subject
|
26
|
+
|
27
|
+
property :subject_scheme_id, as: "SubjectSchemeIdentifier", render_filter: ::ONIX2::Formatters::TWO_DIGITS
|
28
|
+
property :subject_scheme_name, as: "SubjectSchemeName"
|
29
|
+
property :subject_scheme_version, as: "SubjectSchemeVersion"
|
30
|
+
property :subject_code, as: "SubjectCode"
|
31
|
+
property :subject_heading_text, as: "SubjectHeadingText"
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
module ONIX2
|
4
|
+
class SupplyDetail
|
5
|
+
include Virtus.model
|
6
|
+
|
7
|
+
attribute :supplier_ean_location_number
|
8
|
+
attribute :supplier_san
|
9
|
+
attribute :supplier_name
|
10
|
+
attribute :telephone_number
|
11
|
+
attribute :fax_number
|
12
|
+
attribute :email_address
|
13
|
+
attribute :websites, Array[ONIX2::Website]
|
14
|
+
attribute :supplier_role, Integer
|
15
|
+
attribute :supply_to_country
|
16
|
+
attribute :supply_to_territory
|
17
|
+
attribute :availability_status_code, Integer
|
18
|
+
attribute :product_availability, Integer
|
19
|
+
attribute :stock, Array[ONIX2::Stock]
|
20
|
+
attribute :pack_quantity, Integer
|
21
|
+
attribute :prices, Array[ONIX2::Price]
|
22
|
+
|
23
|
+
def to_xml
|
24
|
+
SupplyDetailRepresenter.new(self).to_xml
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.from_xml(data)
|
28
|
+
SupplyDetailRepresenter.new(self.new).from_xml(data)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
class SupplyDetailRepresenter < Representable::Decorator
|
33
|
+
include Representable::XML
|
34
|
+
|
35
|
+
self.representation_wrap = :SupplyDetail
|
36
|
+
|
37
|
+
property :supplier_ean_location_number, as: "SupplierEANLocationNumber"
|
38
|
+
property :supplier_san, as: "SupplierSAN"
|
39
|
+
property :supplier_name, as: "SupplierName"
|
40
|
+
property :telephone_number, as: "TelephoneNumber"
|
41
|
+
property :fax_number, as: "FaxNumber"
|
42
|
+
property :email_address, as: "EmailAddress"
|
43
|
+
collection :websites, as: "Website", extend: ONIX2::WebsiteRepresenter, class: ONIX2::Website
|
44
|
+
property :supplier_role, as: "SupplierRole", render_filter: ::ONIX2::Formatters::TWO_DIGITS
|
45
|
+
property :supply_to_country, as: "SupplyToCountry"
|
46
|
+
property :supply_to_territory, as: "SupplyToTerritory"
|
47
|
+
property :availability_status_code, as: "AvailabilityStatusCode", render_filter: ::ONIX2::Formatters::TWO_DIGITS
|
48
|
+
property :product_availability, as: "ProductAvailability", render_filter: ::ONIX2::Formatters::TWO_DIGITS
|
49
|
+
collection :stock, as: "Stock", extend: ONIX2::StockRepresenter, class: ONIX2::Stock
|
50
|
+
property :pack_quantity, as: "PackQuantity"
|
51
|
+
collection :prices, as: "Price", extend: ONIX2::PriceRepresenter, class: ONIX2::Price
|
52
|
+
end
|
53
|
+
end
|
data/lib/onix2/title.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
module ONIX2
|
4
|
+
class Title
|
5
|
+
include Virtus.model
|
6
|
+
|
7
|
+
attribute :title_type, Integer
|
8
|
+
attribute :title_text
|
9
|
+
attribute :title_prefix
|
10
|
+
attribute :title_without_prefix
|
11
|
+
attribute :subtitle
|
12
|
+
|
13
|
+
def to_xml
|
14
|
+
TitleRepresenter.new(self).to_xml
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.from_xml(data)
|
18
|
+
TitleRepresenter.new(self.new).from_xml(data)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
class TitleRepresenter < Representable::Decorator
|
23
|
+
include Representable::XML
|
24
|
+
|
25
|
+
self.representation_wrap = :Title
|
26
|
+
|
27
|
+
property :title_type, as: "TitleType", render_filter: ::ONIX2::Formatters::TWO_DIGITS
|
28
|
+
property :title_text, as: "TitleText"
|
29
|
+
property :title_prefix, as: "TitlePrefix"
|
30
|
+
property :title_without_prefix, as: "TitleWithoutPrefix"
|
31
|
+
property :subtitle, as: "Subtitle"
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
module ONIX2
|
4
|
+
class Website
|
5
|
+
include Virtus.model
|
6
|
+
|
7
|
+
attribute :website_role, Integer
|
8
|
+
attribute :website_description
|
9
|
+
attribute :website_link
|
10
|
+
|
11
|
+
def to_xml
|
12
|
+
WebsiteRepresenter.new(self).to_xml
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.from_xml(data)
|
16
|
+
WebsiteRepresenter.new(self.new).from_xml(data)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
class WebsiteRepresenter < Representable::Decorator
|
21
|
+
include Representable::XML
|
22
|
+
|
23
|
+
self.representation_wrap = :Website
|
24
|
+
|
25
|
+
property :website_role, as: "WebsiteRole", render_filter: ::ONIX2::Formatters::TWO_DIGITS
|
26
|
+
property :website_description, as: "WebsiteDescription"
|
27
|
+
property :website_link, as: "WebsiteLink"
|
28
|
+
end
|
29
|
+
end
|
data/lib/onix2/writer.rb
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
module ONIX2
|
4
|
+
# The primary way to write a new ONIX file.
|
5
|
+
#
|
6
|
+
# Heres a quick example. The generated file will be nice and boring, as the
|
7
|
+
# header and product objects have no data in them, but you get the idea.
|
8
|
+
#
|
9
|
+
# File.open("output.xml","w") do |output|
|
10
|
+
# header = ONIX2::Header.new
|
11
|
+
# ONIX2::Writer.open(output, header) do |writer|
|
12
|
+
# writer << ONIX2::Product.new
|
13
|
+
# writer << ONIX2::Product.new
|
14
|
+
# end
|
15
|
+
# end
|
16
|
+
#
|
17
|
+
# If you prefer, you can build your products using the APAProduct shim layer.
|
18
|
+
#
|
19
|
+
# File.open("output.xml","w") do |output|
|
20
|
+
# header = ONIX2::Header.new
|
21
|
+
# ONIX2::Writer.open(output, header) do |writer|
|
22
|
+
# writer << ONIX2::APAProduct.new
|
23
|
+
# writer << ONIX2::APAProduct.new
|
24
|
+
# end
|
25
|
+
# end
|
26
|
+
#
|
27
|
+
class Writer
|
28
|
+
|
29
|
+
DOCTYPE = "http://www.editeur.org/onix/2.1/03/reference/onix-international.dtd"
|
30
|
+
|
31
|
+
# Default constructor.
|
32
|
+
def initialize(output, header)
|
33
|
+
raise ArgumentError, 'msg must be an ONIX2::Header object' unless header.kind_of?(ONIX2::Header)
|
34
|
+
@output = output
|
35
|
+
@header = header
|
36
|
+
@finished = false
|
37
|
+
|
38
|
+
start_document
|
39
|
+
end
|
40
|
+
|
41
|
+
# deprecated
|
42
|
+
def start_document
|
43
|
+
puts "ONIX2::StreamWriter#start_document is no longer required"
|
44
|
+
end
|
45
|
+
|
46
|
+
def << (product)
|
47
|
+
unless product.kind_of?(ONIX2::Product) || product.kind_of?(ONIX2::SimpleProduct)
|
48
|
+
raise ArgumentError, 'product must be an ONIX2::Product or ONIX2::SimpleProduct'
|
49
|
+
end
|
50
|
+
raise "Can't add products to a finished writer" if finished?
|
51
|
+
|
52
|
+
@output.write(product.to_xml.to_s)
|
53
|
+
@output.write("\n")
|
54
|
+
end
|
55
|
+
|
56
|
+
def end_document
|
57
|
+
@output.write("</ONIXMessage>\n")
|
58
|
+
@finished = true
|
59
|
+
end
|
60
|
+
|
61
|
+
def finished?
|
62
|
+
@finished
|
63
|
+
end
|
64
|
+
|
65
|
+
def self.open(output, header)
|
66
|
+
if block_given?
|
67
|
+
writer = self.new(output, header)
|
68
|
+
yield writer
|
69
|
+
writer.end_document
|
70
|
+
else
|
71
|
+
self.new(output, header)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
private
|
76
|
+
|
77
|
+
def start_document
|
78
|
+
@output.write("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n")
|
79
|
+
@output.write("<!DOCTYPE ONIXMessage SYSTEM \"#{DOCTYPE}\">\n")
|
80
|
+
@output.write("<ONIXMessage release=\"2.1\">\n")
|
81
|
+
@output.write(@header.to_xml.to_s)
|
82
|
+
@output.write("\n")
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|
86
|
+
end
|