milkfarm-onix 0.7.7
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +136 -0
- data/README.markdown +40 -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/onix/addressee_identifier.rb +12 -0
- data/lib/onix/apa_product.rb +731 -0
- data/lib/onix/audience_range.rb +26 -0
- data/lib/onix/common.rb +26 -0
- data/lib/onix/contributor.rb +27 -0
- data/lib/onix/header.rb +46 -0
- data/lib/onix/imprint.rb +15 -0
- data/lib/onix/language.rb +14 -0
- data/lib/onix/lists/audience_code.rb +17 -0
- data/lib/onix/lists/country_code.rb +257 -0
- data/lib/onix/lists/language_code.rb +498 -0
- data/lib/onix/lists/language_role.rb +18 -0
- data/lib/onix/lists/notification_type.rb +19 -0
- data/lib/onix/lists/product_availability.rb +32 -0
- data/lib/onix/lists/product_form.rb +99 -0
- data/lib/onix/lists/product_form_detail.rb +157 -0
- data/lib/onix/market_representation.rb +19 -0
- data/lib/onix/measure.rb +14 -0
- data/lib/onix/media_file.rb +16 -0
- data/lib/onix/normaliser.rb +187 -0
- data/lib/onix/other_text.rb +17 -0
- data/lib/onix/price.rb +21 -0
- data/lib/onix/product.rb +73 -0
- data/lib/onix/product_identifier.rb +13 -0
- data/lib/onix/publisher.rb +16 -0
- data/lib/onix/reader.rb +187 -0
- data/lib/onix/sales_restriction.rb +12 -0
- data/lib/onix/sender_identifier.rb +14 -0
- data/lib/onix/series.rb +57 -0
- data/lib/onix/series_identifier.rb +13 -0
- data/lib/onix/simple_product.rb +47 -0
- data/lib/onix/sl_product.rb +131 -0
- data/lib/onix/stock.rb +15 -0
- data/lib/onix/subject.rb +16 -0
- data/lib/onix/supply_detail.rb +32 -0
- data/lib/onix/title.rb +17 -0
- data/lib/onix/website.rb +14 -0
- data/lib/onix/writer.rb +86 -0
- data/lib/onix.rb +114 -0
- data/spec/apa_product_spec.rb +59 -0
- data/spec/audience_range_spec.rb +46 -0
- data/spec/contributor_spec.rb +42 -0
- data/spec/header_spec.rb +123 -0
- data/spec/imprint_spec.rb +39 -0
- data/spec/language_spec.rb +42 -0
- data/spec/market_representation_spec.rb +41 -0
- data/spec/measure_spec.rb +43 -0
- data/spec/media_file_spec.rb +42 -0
- data/spec/normaliser_spec.rb +125 -0
- data/spec/other_text_spec.rb +40 -0
- data/spec/price_spec.rb +40 -0
- data/spec/product_identifier_spec.rb +40 -0
- data/spec/product_spec.rb +96 -0
- data/spec/publisher_spec.rb +38 -0
- data/spec/reader_spec.rb +131 -0
- data/spec/sales_restriction_spec.rb +35 -0
- data/spec/sender_identifier.rb +40 -0
- data/spec/series_identifier_spec.rb +38 -0
- data/spec/series_spec.rb +34 -0
- data/spec/sl_product_spec.rb +48 -0
- data/spec/stock_spec.rb +44 -0
- data/spec/subject_spec.rb +40 -0
- data/spec/supply_detail_spec.rb +53 -0
- data/spec/title_spec.rb +43 -0
- data/spec/website_spec.rb +41 -0
- data/spec/writer_spec.rb +81 -0
- data/support/entities.txt +1499 -0
- data/support/extract.rb +25 -0
- data/support/switch-onix-2.1-short-to-reference.xsl +23 -0
- data/support/switch-onix-tagnames-1.1.xsl +25 -0
- data/support/switch-onix-tagnames-2.0.xsl +37 -0
- metadata +209 -0
@@ -0,0 +1,157 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
module ONIX
|
4
|
+
module Lists
|
5
|
+
# Code list 78
|
6
|
+
PRODUCT_FORM_DETAIL = {
|
7
|
+
"A101" => "CD standard audio format",
|
8
|
+
"A102" => "SACD super audio format",
|
9
|
+
"A103" => "MP3 format",
|
10
|
+
"A104" => "WAV format",
|
11
|
+
"A105" => "Real Audio format",
|
12
|
+
"A106" => "WMA",
|
13
|
+
"A107" => "AAC",
|
14
|
+
"A108" => "Ogg/Vorbis",
|
15
|
+
"A109" => "Audible",
|
16
|
+
"A110" => "FLAC",
|
17
|
+
"A111" => "AIFF",
|
18
|
+
"A112" => "ALAC",
|
19
|
+
"A201" => "DAISY 2: full audio with title only (no navigation)",
|
20
|
+
"A202" => "DAISY 2: full audio with navigation",
|
21
|
+
"A203" => "DAISY 2: full audio with navigation and partial text",
|
22
|
+
"A204" => "DAISY 2: full audio and full text",
|
23
|
+
"A205" => "DAISY 2: full text and some audio",
|
24
|
+
"A206" => "DAISY 2: full text and no audio",
|
25
|
+
"A207" => "DAISY 3: full audio with title only (no navigation)",
|
26
|
+
"A208" => "DAISY 3: full audio with navigation",
|
27
|
+
"A209" => "DAISY 3: full audio with navigation and partial text",
|
28
|
+
"A210" => "DAISY 3: full audio and full text",
|
29
|
+
"A211" => "DAISY 3: full text and some audio",
|
30
|
+
"A212" => "DAISY 3: full text and no audio",
|
31
|
+
"B101" => "Mass market (rack) paperback",
|
32
|
+
"B102" => "Trade paperback (US)",
|
33
|
+
"B103" => "Digest format paperback",
|
34
|
+
"B104" => "A-format paperback",
|
35
|
+
"B105" => "B-format paperback",
|
36
|
+
"B106" => "Trade paperback (UK)",
|
37
|
+
"B107" => "Tall rack paperback (US)",
|
38
|
+
"B108" => "A5: Tankobon",
|
39
|
+
"B109" => "B5: Tankobon",
|
40
|
+
"B110" => "B6: Tankobon",
|
41
|
+
"B111" => "A6: Bunko",
|
42
|
+
"B112" => "B40-dori: Shinsho",
|
43
|
+
"B113" => "Pocket (Sweden)",
|
44
|
+
"B114" => "Storpocket (Sweden)",
|
45
|
+
"B115" => "Kartonnage (Sweden)",
|
46
|
+
"B116" => "Flexband (Sweden)",
|
47
|
+
"B201" => "Coloring / join-the-dot book",
|
48
|
+
"B202" => "Lift-the-flap book",
|
49
|
+
"B203" => "Fuzzy book",
|
50
|
+
"B204" => "Miniature book",
|
51
|
+
"B205" => "Moving picture / flicker book",
|
52
|
+
"B206" => "Pop-up book",
|
53
|
+
"B207" => "Scented / 'smelly' book",
|
54
|
+
"B208" => "Sound story / 'noisy' book",
|
55
|
+
"B209" => "Sticker book",
|
56
|
+
"B210" => "Touch-and-feel book",
|
57
|
+
"B211" => "Toy / die-cut book",
|
58
|
+
"B212" => "Die-cut book",
|
59
|
+
"B213" => "Book-as-toy",
|
60
|
+
"B214" => "Soft-to-touch book",
|
61
|
+
"B215" => "Fuzzy-felt book",
|
62
|
+
"B221" => "Picture book",
|
63
|
+
"B301" => "Loose leaf - sheets & binder",
|
64
|
+
"B302" => "Loose leaf - binder only",
|
65
|
+
"B303" => "Loose leaf - sheets only",
|
66
|
+
"B304" => "Sewn",
|
67
|
+
"B305" => "Unsewn / adhesive bound",
|
68
|
+
"B306" => "Library binding",
|
69
|
+
"B307" => "Reinforced binding",
|
70
|
+
"B308" => "Half bound",
|
71
|
+
"B309" => "Quarter bound",
|
72
|
+
"B310" => "Saddle-sewn",
|
73
|
+
"B311" => "Comb bound",
|
74
|
+
"B312" => "Wire-O",
|
75
|
+
"B313" => "Concealed wire",
|
76
|
+
"B401" => "Cloth over boards",
|
77
|
+
"B402" => "Paper over boards",
|
78
|
+
"B403" => "Leather, real",
|
79
|
+
"B404" => "Leather, imitation",
|
80
|
+
"B405" => "Leather, bonded",
|
81
|
+
"B406" => "Vellum",
|
82
|
+
"B407" => "Plastic",
|
83
|
+
"B408" => "Vinyl",
|
84
|
+
"B409" => "Cloth",
|
85
|
+
"B410" => "Imitation cloth",
|
86
|
+
"B411" => "Velvet",
|
87
|
+
"B412" => "Flexible plastic/vinyl cover",
|
88
|
+
"B413" => "Plastic-covered",
|
89
|
+
"B414" => "Vinyl-covered",
|
90
|
+
"B415" => "Laminated cover",
|
91
|
+
"B501" => "With dust jacket",
|
92
|
+
"B502" => "With printed dust jacket",
|
93
|
+
"B503" => "With translucent dust cover",
|
94
|
+
"B504" => "With flaps",
|
95
|
+
"B505" => "With thumb index",
|
96
|
+
"B506" => "With ribbon marker(s)",
|
97
|
+
"B507" => "With zip fastener",
|
98
|
+
"B508" => "With button snap fastener",
|
99
|
+
"B509" => "With leather edge lining",
|
100
|
+
"B601" => "Turn-around book",
|
101
|
+
"B602" => "Unflipped manga format",
|
102
|
+
"B701" => "UK Braille Grade 1",
|
103
|
+
"B702" => "UK Braille Grade 2",
|
104
|
+
"B703" => "US Braille",
|
105
|
+
"D101" => "Real Video format",
|
106
|
+
"D102" => "Quicktime format",
|
107
|
+
"D103" => "AVI format",
|
108
|
+
"D104" => "Windows Media Video format",
|
109
|
+
"D105" => "MPEG-4",
|
110
|
+
"D201" => "MS-DOS",
|
111
|
+
"D202" => "Windows",
|
112
|
+
"D203" => "Macintosh",
|
113
|
+
"D204" => "UNIX / LINUX",
|
114
|
+
"D205" => "Other operating system(s)",
|
115
|
+
"D206" => "Palm OS",
|
116
|
+
"D207" => "Windows Mobile",
|
117
|
+
"D301" => "Microsoft XBox",
|
118
|
+
"D302" => "Nintendo Gameboy Color",
|
119
|
+
"D303" => "Nintendo Gameboy Advanced",
|
120
|
+
"D304" => "Nintendo Gameboy",
|
121
|
+
"D305" => "Nintendo Gamecube",
|
122
|
+
"D306" => "Nintendo 64",
|
123
|
+
"D307" => "Sega Dreamcast",
|
124
|
+
"D308" => "Sega Genesis/Megadrive",
|
125
|
+
"D309" => "Sega Saturn",
|
126
|
+
"D310" => "Sony PlayStation 1",
|
127
|
+
"D311" => "Sony PlayStation 2",
|
128
|
+
"D312" => "Nintendo Dual Screen",
|
129
|
+
"D313" => "Sony PlayStation 3",
|
130
|
+
"D314" => "Xbox 360",
|
131
|
+
"D315" => "Nintendo Wii",
|
132
|
+
"D316" => "Sony PlayStation Portable (PSP)",
|
133
|
+
"L101" => "Laminated",
|
134
|
+
"P101" => "Desk calendar",
|
135
|
+
"P102" => "Mini calendar",
|
136
|
+
"P103" => "Engagement calendar",
|
137
|
+
"P104" => "Day by day calendar",
|
138
|
+
"P105" => "Poster calendar",
|
139
|
+
"P106" => "Wall calendar",
|
140
|
+
"P107" => "Perpetual calendar",
|
141
|
+
"P108" => "Advent calendar",
|
142
|
+
"P109" => "Bookmark calendar",
|
143
|
+
"P110" => "Student calendar",
|
144
|
+
"P111" => "Project calendar",
|
145
|
+
"P112" => "Almanac calendar",
|
146
|
+
"P113" => "Other calendar",
|
147
|
+
"P114" => "Other calendar or organiser product",
|
148
|
+
"P201" => "Hardback (stationery)",
|
149
|
+
"P202" => "Paperback / softback (stationery)",
|
150
|
+
"P203" => "Spiral bound (stationery)",
|
151
|
+
"P204" => "Leather / fine binding (stationery)",
|
152
|
+
"V201" => "PAL",
|
153
|
+
"V202" => "NTSC",
|
154
|
+
"V203" => "SECAM",
|
155
|
+
}
|
156
|
+
end
|
157
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
module ONIX
|
4
|
+
class MarketRepresentation
|
5
|
+
include ROXML
|
6
|
+
include ONIX::Common
|
7
|
+
|
8
|
+
xml_name "MarketRepresentation"
|
9
|
+
|
10
|
+
xml_accessor :agent_name, :from => "AgentName"
|
11
|
+
xml_accessor :agent_role, :from => "AgentRole", :as => Fixnum, :to_xml => ONIX::Formatters.two_digit
|
12
|
+
xml_accessor :market_country, :from => "MarketCountry"
|
13
|
+
xml_accessor :market_territory, :from => "MarketTerritory"
|
14
|
+
xml_accessor :market_country_excluded, :from => "MarketCountryExcluded"
|
15
|
+
xml_accessor :market_restriction_detail, :from => "MarketRestrictionDetail"
|
16
|
+
xml_accessor :market_publishing_status, :from => "MarketPublishingStatus", :as => Fixnum, :to_xml => ONIX::Formatters.two_digit
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
data/lib/onix/measure.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
module ONIX
|
4
|
+
class Measure
|
5
|
+
include ROXML
|
6
|
+
include ONIX::Common
|
7
|
+
|
8
|
+
xml_name "Measure"
|
9
|
+
|
10
|
+
xml_accessor :measure_type_code, :from => "MeasureTypeCode", :as => Fixnum, :to_xml => ONIX::Formatters.two_digit
|
11
|
+
xml_accessor :measurement, :from => "Measurement", :as => BigDecimal
|
12
|
+
xml_accessor :measure_unit_code, :from => "MeasureUnitCode"
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
module ONIX
|
4
|
+
class MediaFile
|
5
|
+
include ROXML
|
6
|
+
include ONIX::Common
|
7
|
+
|
8
|
+
xml_name "MediaFile"
|
9
|
+
|
10
|
+
xml_accessor :media_file_type_code, :from => "MediaFileTypeCode", :as => Fixnum, :to_xml => ONIX::Formatters.two_digit
|
11
|
+
xml_accessor :media_file_format_code, :from => "MediaFileFormatCode", :as => Fixnum, :to_xml => ONIX::Formatters.two_digit
|
12
|
+
xml_accessor :image_resolution, :from => "ImageResolution"
|
13
|
+
xml_accessor :media_file_link_type_code, :from => "MediaFileLinkTypeCode", :as => Fixnum, :to_xml => ONIX::Formatters.two_digit
|
14
|
+
xml_accessor :media_file_link, :from => "MediaFileLink"
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,187 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
require 'tempfile'
|
4
|
+
require 'fileutils'
|
5
|
+
|
6
|
+
module ONIX
|
7
|
+
|
8
|
+
# A standalone class that can be used to normalise ONIX files
|
9
|
+
# into a standardised form. If you're accepting ONIX files from a wide range
|
10
|
+
# of suppliers, you're guarunteed to get all sorts of dialects.
|
11
|
+
#
|
12
|
+
# This will create a new file that:
|
13
|
+
#
|
14
|
+
# - is UTF-8 encoded
|
15
|
+
# - uses reference tags, not short
|
16
|
+
# - has no named entities (ndash, etc) other than & < and >
|
17
|
+
#
|
18
|
+
# Usage:
|
19
|
+
#
|
20
|
+
# ONIX::Normaliser.process("oldfile.xml", "newfile.xml")
|
21
|
+
#
|
22
|
+
# Dependencies:
|
23
|
+
#
|
24
|
+
# At this stage the class depends on several external apps, all commonly available
|
25
|
+
# on *nix systems: xsltproc, isutf8, iconv and sed
|
26
|
+
#
|
27
|
+
class Normaliser
|
28
|
+
|
29
|
+
class << self
|
30
|
+
|
31
|
+
# normalise oldfile and save it as newfile. oldfile
|
32
|
+
# will be left untouched
|
33
|
+
#
|
34
|
+
def process(oldfile, newfile)
|
35
|
+
self.new(oldfile, newfile).run
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def initialize(oldfile, newfile)
|
40
|
+
raise ArgumentError, "#{oldfile} does not exist" unless File.file?(oldfile)
|
41
|
+
raise ArgumentError, "#{newfile} already exists" if File.file?(newfile)
|
42
|
+
raise "xsltproc app not found" unless app_available?("xsltproc")
|
43
|
+
raise "isutf8 app not found" unless app_available?("isutf8")
|
44
|
+
raise "iconv app not found" unless app_available?("iconv")
|
45
|
+
raise "sed app not found" unless app_available?("sed")
|
46
|
+
raise "tr app not found" unless app_available?("tr")
|
47
|
+
|
48
|
+
@oldfile = oldfile
|
49
|
+
@newfile = newfile
|
50
|
+
@curfile = next_tempfile
|
51
|
+
FileUtils.cp(@oldfile, @curfile)
|
52
|
+
@head = File.open(@oldfile, "r") { |f| f.read(1024) }
|
53
|
+
end
|
54
|
+
|
55
|
+
def run
|
56
|
+
# remove short tags
|
57
|
+
if @head.include?("ONIXmessage")
|
58
|
+
dest = next_tempfile
|
59
|
+
to_reference_tags(@curfile, dest)
|
60
|
+
@curfile = dest
|
61
|
+
end
|
62
|
+
|
63
|
+
# convert to utf8
|
64
|
+
dest = next_tempfile
|
65
|
+
to_utf8(@curfile, dest)
|
66
|
+
@curfile = dest
|
67
|
+
|
68
|
+
# remove control chars
|
69
|
+
dest = next_tempfile
|
70
|
+
remove_control_chars(@curfile, dest)
|
71
|
+
@curfile = dest
|
72
|
+
|
73
|
+
# remove entities
|
74
|
+
dest = next_tempfile
|
75
|
+
replace_named_entities(@curfile, dest)
|
76
|
+
@curfile = dest
|
77
|
+
|
78
|
+
FileUtils.cp(@curfile, @newfile)
|
79
|
+
end
|
80
|
+
|
81
|
+
#private
|
82
|
+
|
83
|
+
# check the specified app is available on the system
|
84
|
+
#
|
85
|
+
def app_available?(app)
|
86
|
+
`which #{app}`.strip == "" ? false : true
|
87
|
+
end
|
88
|
+
|
89
|
+
# generate a temp filename
|
90
|
+
#
|
91
|
+
def next_tempfile
|
92
|
+
p = nil
|
93
|
+
Tempfile.open("onix") do |tf|
|
94
|
+
tf.close
|
95
|
+
p = tf.path
|
96
|
+
end
|
97
|
+
p
|
98
|
+
end
|
99
|
+
|
100
|
+
# uses an XSLT stylesheet provided by edituer to convert
|
101
|
+
# a file from short tags to long tags.
|
102
|
+
#
|
103
|
+
# more detail here:
|
104
|
+
# http://www.editeur.org/files/ONIX%203/ONIX%20tagname%20converter%20v2.htm
|
105
|
+
#
|
106
|
+
def to_reference_tags(src, dest)
|
107
|
+
inpath = File.expand_path(src)
|
108
|
+
outpath = File.expand_path(dest)
|
109
|
+
xsltpath = File.dirname(__FILE__) + "/../../support/switch-onix-2.1-short-to-reference.xsl"
|
110
|
+
`xsltproc -o #{outpath} #{xsltpath} #{inpath}`
|
111
|
+
end
|
112
|
+
|
113
|
+
# ensure the file is valid utf8, then make sure it's declared as such.
|
114
|
+
#
|
115
|
+
# The following behaviour is expected:
|
116
|
+
#
|
117
|
+
# file is valid utf8, is marked correctly
|
118
|
+
# - copied untouched
|
119
|
+
# file is valid utf8, is marked incorrectly or has no marked encoding
|
120
|
+
# - copied and encoding mark fixed or added
|
121
|
+
# file is no utf8, encoding is marked
|
122
|
+
# - file is converted to utf8 and enecoding mark is updated
|
123
|
+
# file is not utf8, encoding is not marked
|
124
|
+
# - file is copied untouched
|
125
|
+
#
|
126
|
+
def to_utf8(src, dest)
|
127
|
+
inpath = File.expand_path(src)
|
128
|
+
outpath = File.expand_path(dest)
|
129
|
+
|
130
|
+
m, src_enc = *@head.match(/encoding=.([a-zA-Z0-9\-]+)./i)
|
131
|
+
|
132
|
+
# ensure the file is actually utf8
|
133
|
+
if `isutf8 #{inpath}`.strip == ""
|
134
|
+
if src_enc.to_s.downcase == "utf-8"
|
135
|
+
FileUtils.cp(inpath, outpath)
|
136
|
+
else
|
137
|
+
FileUtils.cp(inpath, outpath)
|
138
|
+
`sed -i 's/<?xml.*?>/<?xml version=\"1.0\" encoding=\"UTF-8\"?>/g' #{outpath}`
|
139
|
+
end
|
140
|
+
elsif src_enc
|
141
|
+
`iconv --from-code=#{src_enc} --to-code=UTF-8 #{inpath} > #{outpath}`
|
142
|
+
`sed -i 's/#{src_enc}/UTF-8/' #{outpath}`
|
143
|
+
else
|
144
|
+
FileUtils.cp(inpath, outpath)
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
# XML files shouldn't contain low ASCII control chars. Strip them.
|
149
|
+
#
|
150
|
+
def remove_control_chars(src, dest)
|
151
|
+
inpath = File.expand_path(src)
|
152
|
+
outpath = File.expand_path(dest)
|
153
|
+
`cat #{inpath} | tr -d "\\000-\\010\\013\\014\\016-\\037" > #{outpath}`
|
154
|
+
end
|
155
|
+
|
156
|
+
# replace all named entities in the specified file with
|
157
|
+
# numeric entities.
|
158
|
+
#
|
159
|
+
def replace_named_entities(src, dest)
|
160
|
+
inpath = File.expand_path(src)
|
161
|
+
outpath = File.expand_path(dest)
|
162
|
+
|
163
|
+
cmd = "sed " + entity_map.map do |named, numeric|
|
164
|
+
"-e 's/\\&#{named};/\\&#{numeric};/g'"
|
165
|
+
end.join(" ") + " #{inpath} > #{outpath}"
|
166
|
+
#raise cmd
|
167
|
+
`#{cmd}`
|
168
|
+
end
|
169
|
+
|
170
|
+
# return a named entity to numeric entity mapping, build by extracting
|
171
|
+
# data from the ONIX DTD
|
172
|
+
#
|
173
|
+
def entity_map
|
174
|
+
return @map if @map
|
175
|
+
|
176
|
+
path = File.dirname(__FILE__) + "/../../support/entities.txt"
|
177
|
+
@map = {}
|
178
|
+
File.read(path).split.each do |line|
|
179
|
+
elements = line.split(":")
|
180
|
+
@map[elements.first] = elements.last
|
181
|
+
end
|
182
|
+
@map
|
183
|
+
end
|
184
|
+
|
185
|
+
end
|
186
|
+
|
187
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
module ONIX
|
4
|
+
class OtherText
|
5
|
+
include ROXML
|
6
|
+
include ONIX::Common
|
7
|
+
|
8
|
+
xml_name "OtherText"
|
9
|
+
|
10
|
+
xml_accessor :text_type_code, :from => "TextTypeCode", :as => Fixnum, :to_xml => ONIX::Formatters.two_digit
|
11
|
+
xml_accessor :text_format, :from => "TextFormat"
|
12
|
+
xml_accessor :text, :from => "Text"
|
13
|
+
xml_accessor :text_link_type, :from => "TextLinkType", :as => Fixnum, :to_xml => ONIX::Formatters.two_digit
|
14
|
+
xml_accessor :text_link, :from => "TextLink"
|
15
|
+
xml_accessor :text_author, :from => "TextAuthor"
|
16
|
+
end
|
17
|
+
end
|
data/lib/onix/price.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
module ONIX
|
4
|
+
class Price
|
5
|
+
include ROXML
|
6
|
+
include ONIX::Common
|
7
|
+
|
8
|
+
xml_name "Price"
|
9
|
+
|
10
|
+
xml_accessor :price_type_code, :from => "PriceTypeCode", :as => Fixnum, :to_xml => ONIX::Formatters.two_digit
|
11
|
+
xml_accessor :price_type_qualifier, :from => "PriceTypeQualifier", :as => Fixnum, :to_xml => ONIX::Formatters.two_digit
|
12
|
+
xml_accessor :price_type_description, :from => "PriceTypeDescription"
|
13
|
+
xml_accessor :price_per, :from => "PricePer", :as => Fixnum, :to_xml => ONIX::Formatters.two_digit
|
14
|
+
xml_accessor :minimum_order_qty, :from => "MinimumOrderQuantity", :as => Fixnum
|
15
|
+
xml_accessor :class_of_trade, :from => "ClassOfTrade"
|
16
|
+
xml_accessor :bic_discount_group_code, :from => "BICDiscountGroupCode"
|
17
|
+
xml_accessor :price_status, :from => "PriceStatus", :as => Fixnum, :to_xml => ONIX::Formatters.two_digit
|
18
|
+
xml_accessor :price_amount, :from => "PriceAmount", :as => BigDecimal, :to_xml => ONIX::Formatters.decimal
|
19
|
+
xml_accessor :currency_code, :from => "CurrencyCode"
|
20
|
+
end
|
21
|
+
end
|
data/lib/onix/product.rb
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
module ONIX
|
4
|
+
class Product
|
5
|
+
include ROXML
|
6
|
+
include ONIX::Common
|
7
|
+
|
8
|
+
xml_name "Product"
|
9
|
+
|
10
|
+
xml_accessor :record_reference, :from => "RecordReference"
|
11
|
+
xml_accessor :notification_type, :from => "NotificationType", :as => Fixnum, :to_xml => ONIX::Formatters.two_digit
|
12
|
+
xml_accessor :product_identifiers, :from => "ProductIdentifier", :as => [ONIX::ProductIdentifier]
|
13
|
+
xml_accessor :product_form, :from => "ProductForm"
|
14
|
+
xml_accessor :product_form_detail, :from => "ProductFormDetail"
|
15
|
+
xml_accessor :series, :from => "Series", :as => [ONIX::Series]
|
16
|
+
xml_accessor :titles, :from => "Title", :as => [ONIX::Title]
|
17
|
+
xml_accessor :websites, :from => "Website", :as => [ONIX::Website]
|
18
|
+
xml_accessor :contributors, :from => "Contributor", :as => [ONIX::Contributor]
|
19
|
+
xml_accessor :edition_number, :from => "EditionNumber", :as => Fixnum
|
20
|
+
xml_accessor :languages, :from => "Language", :as => [ONIX::Language]
|
21
|
+
xml_accessor :number_of_pages, :from => "NumberOfPages", :as => Fixnum
|
22
|
+
xml_accessor :bic_main_subject, :from => "BICMainSubject"
|
23
|
+
xml_accessor :subjects, :from => "Subject", :as => [ONIX::Subject]
|
24
|
+
xml_accessor :audience_code, :from => "AudienceCode", :to_xml => ONIX::Formatters.two_digit
|
25
|
+
xml_accessor :audience_ranges, :from => "AudienceRange", :as => [ONIX::AudienceRange]
|
26
|
+
xml_accessor :text, :from => "OtherText", :as => [ONIX::OtherText]
|
27
|
+
xml_accessor :media_files, :from => "MediaFile", :as => [ONIX::MediaFile]
|
28
|
+
xml_accessor :imprints, :from => "Imprint", :as => [ONIX::Imprint]
|
29
|
+
xml_accessor :publishers, :from => "Publisher", :as => [ONIX::Publisher]
|
30
|
+
xml_accessor :publishing_status, :from => "PublishingStatus", :as => Fixnum, :to_xml => ONIX::Formatters.two_digit
|
31
|
+
xml_accessor(:publication_date, :from => "PublicationDate", :to_xml => ONIX::Formatters.yyyymmdd) do |val|
|
32
|
+
begin
|
33
|
+
Date.parse(val)
|
34
|
+
rescue
|
35
|
+
nil
|
36
|
+
end
|
37
|
+
end
|
38
|
+
xml_accessor :copyright_year, :from => "CopyrightYear", :as => Integer
|
39
|
+
xml_accessor :year_first_published, :from => "YearFirstPublished", :as => Fixnum
|
40
|
+
xml_accessor :sales_restrictions, :from => "SalesRestriction", :as => [ONIX::SalesRestriction]
|
41
|
+
xml_accessor :measurements, :from => "Measure", :as => [ONIX::Measure]
|
42
|
+
xml_accessor :supply_details, :from => "SupplyDetail", :as => [ONIX::SupplyDetail]
|
43
|
+
xml_accessor :market_representations, :from => "MarketRepresentation", :as => [ONIX::MarketRepresentation]
|
44
|
+
|
45
|
+
# some deprecated attributes. Read only
|
46
|
+
# - See the measures array for the current way of specifying
|
47
|
+
# various measurements of the product
|
48
|
+
xml_reader :height, :from => "Height", :as => BigDecimal
|
49
|
+
xml_reader :width, :from => "Width", :as => BigDecimal
|
50
|
+
xml_reader :thickness, :from => "Thickness", :as => BigDecimal
|
51
|
+
xml_reader :weight, :from => "Weight", :as => BigDecimal
|
52
|
+
xml_reader :dimensions, :from => "Dimensions"
|
53
|
+
|
54
|
+
def initialize
|
55
|
+
self.product_identifiers = []
|
56
|
+
self.series = []
|
57
|
+
self.titles = []
|
58
|
+
self.contributors = []
|
59
|
+
self.websites = []
|
60
|
+
self.subjects = []
|
61
|
+
self.audience_ranges = []
|
62
|
+
self.text = []
|
63
|
+
self.languages = []
|
64
|
+
self.media_files = []
|
65
|
+
self.imprints = []
|
66
|
+
self.publishers = []
|
67
|
+
self.sales_restrictions = []
|
68
|
+
self.measurements = []
|
69
|
+
self.supply_details = []
|
70
|
+
self.market_representations = []
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
module ONIX
|
4
|
+
class ProductIdentifier
|
5
|
+
include ROXML
|
6
|
+
include ONIX::Common
|
7
|
+
|
8
|
+
xml_name "ProductIdentifier"
|
9
|
+
|
10
|
+
xml_accessor :product_id_type, :from => "ProductIDType", :as => Fixnum, :to_xml => ONIX::Formatters.two_digit
|
11
|
+
xml_accessor :id_value, :from => "IDValue"
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
module ONIX
|
4
|
+
class Publisher
|
5
|
+
include ROXML
|
6
|
+
include ONIX::Common
|
7
|
+
|
8
|
+
xml_name "Publisher"
|
9
|
+
|
10
|
+
xml_accessor :publishing_role, :from => "PublishingRole", :as => Fixnum, :to_xml => ONIX::Formatters.two_digit
|
11
|
+
xml_accessor :name_code_type, :from => "NameCodeType", :as => Fixnum, :to_xml => ONIX::Formatters.two_digit
|
12
|
+
xml_accessor :name_code_type_name, :from => "NameCodeTypeName"
|
13
|
+
xml_accessor :name_code_type_value, :from => "NameCodeTypeValue"
|
14
|
+
xml_accessor :publisher_name, :from => "PublisherName"
|
15
|
+
end
|
16
|
+
end
|