rbook 0.4.3 → 0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +13 -176
- metadata +57 -117
- data/COPYING +0 -340
- data/LICENSE +0 -13
- data/README +0 -17
- data/examples/gbip.rb +0 -12
- data/examples/onix/stream_reader.rb +0 -13
- data/examples/pacstream.rb +0 -13
- data/examples/titlepage.rb +0 -14
- data/examples/titlepage_with_proxy.rb +0 -14
- data/examples/titlepage_www.rb +0 -18
- data/examples/www/find_all.rb +0 -23
- data/examples/www/find_cover_from_amazon.rb +0 -16
- data/examples/www/find_url_from_rainbow.rb +0 -12
- data/examples/www/list.rb +0 -13
- data/lib/rbook/bisac.rb +0 -31
- data/lib/rbook/bisac/message.rb +0 -99
- data/lib/rbook/bisac/po.rb +0 -97
- data/lib/rbook/bisac/po_line_item.rb +0 -33
- data/lib/rbook/bisac/product.rb +0 -176
- data/lib/rbook/errors.rb +0 -8
- data/lib/rbook/gbip.rb +0 -21
- data/lib/rbook/gbip/pos.rb +0 -118
- data/lib/rbook/gbip/title.rb +0 -36
- data/lib/rbook/gbip/warehouse.rb +0 -27
- data/lib/rbook/isbn.rb +0 -255
- data/lib/rbook/onix.rb +0 -70
- data/lib/rbook/onix/contributor.rb +0 -60
- data/lib/rbook/onix/lists.rb +0 -2
- data/lib/rbook/onix/lists/contributor_role.rb +0 -10
- data/lib/rbook/onix/lists/product_form.rb +0 -100
- data/lib/rbook/onix/message.rb +0 -112
- data/lib/rbook/onix/product.rb +0 -189
- data/lib/rbook/onix/sales_restriction.rb +0 -51
- data/lib/rbook/onix/stream_reader.rb +0 -120
- data/lib/rbook/onix/stream_writer.rb +0 -40
- data/lib/rbook/onix/supply_detail.rb +0 -68
- data/lib/rbook/onix/xchar.rb +0 -98
- data/lib/rbook/pacstream.rb +0 -64
- data/lib/rbook/titlepage.rb +0 -37
- data/lib/rbook/titlepage/client.rb +0 -126
- data/lib/rbook/titlepage/titlepage_driver.rb +0 -137
- data/lib/rbook/titlepage/titlepage_utils.rb +0 -379
- data/lib/rbook/titlepage/wwwclient.rb +0 -96
- data/lib/rbook/www.rb +0 -172
- data/lib/rbook/www/aau_scraper.rb +0 -76
- data/lib/rbook/www/amazon_uk_scraper.rb +0 -44
- data/lib/rbook/www/ban_scraper.rb +0 -62
- data/lib/rbook/www/base.rb +0 -87
- data/lib/rbook/www/harper_au_scraper.rb +0 -56
- data/lib/rbook/www/harper_us_scraper.rb +0 -55
- data/lib/rbook/www/hha_scraper.rb +0 -50
- data/lib/rbook/www/macmillan_scraper.rb +0 -62
- data/lib/rbook/www/orbis_scraper.rb +0 -48
- data/lib/rbook/www/oup_scraper.rb +0 -64
- data/lib/rbook/www/paulist_scraper.rb +0 -53
- data/lib/rbook/www/pearson_au_scraper.rb +0 -52
- data/lib/rbook/www/penguin_scraper.rb +0 -45
- data/lib/rbook/www/random_au_scraper.rb +0 -90
- data/lib/rbook/www/random_us_scraper.rb +0 -59
- data/lib/rbook/www/sas_scraper.rb +0 -54
- data/lib/rbook/www/unireps_scraper.rb +0 -58
- data/lib/rbook/www/wiley_us_scraper.rb +0 -54
- data/test/data/abingdon.xml +0 -38931
- data/test/data/augsburg.xml +0 -39009
- data/test/data/bisac_po.txt +0 -112
- data/test/data/chalice.xml +0 -10851
- data/test/data/eerdsman.xml +0 -36942
- data/test/data/invalid_no_product.xml +0 -9
- data/test/data/not_xml.csv +0 -1
- data/test/data/single_product.xml +0 -50
- data/test/data/valid_bisac.txt +0 -213
- data/test/data/xml_not_onix.xml +0 -7
- data/test/mocks/titlepage_driver.rb +0 -111
- data/test/unit/bisac/bisac_test.rb +0 -96
- data/test/unit/bisac/po_line_item_test.rb +0 -38
- data/test/unit/bisac/po_test.rb +0 -82
- data/test/unit/isbn_test.rb +0 -153
- data/test/unit/onix/contributor_test.rb +0 -50
- data/test/unit/onix/message_test.rb +0 -119
- data/test/unit/onix/product_test.rb +0 -101
- data/test/unit/onix/sales_restriction_test.rb +0 -48
- data/test/unit/onix/stream_reader_test.rb +0 -22
- data/test/unit/onix/stream_writer_test.rb +0 -32
- data/test/unit/onix/supply_detail_test.rb +0 -53
- data/test/unit/onix/xchar_test.rb +0 -37
- data/test/unit/titlepage_test.rb +0 -140
data/lib/rbook/onix.rb
DELETED
@@ -1,70 +0,0 @@
|
|
1
|
-
$LOAD_PATH.unshift(File.dirname(__FILE__) + "/../")
|
2
|
-
|
3
|
-
require 'rbook/onix/contributor'
|
4
|
-
require 'rbook/onix/lists'
|
5
|
-
require 'rbook/onix/message'
|
6
|
-
require 'rbook/onix/product'
|
7
|
-
require 'rbook/onix/sales_restriction'
|
8
|
-
require 'rbook/onix/supply_detail'
|
9
|
-
require 'rbook/onix/xchar'
|
10
|
-
require 'rbook/onix/stream_reader'
|
11
|
-
require 'rbook/onix/stream_writer'
|
12
|
-
require 'rbook/isbn'
|
13
|
-
|
14
|
-
module RBook
|
15
|
-
|
16
|
-
# Ruby classes for working with ONIX files. Currently only supports a very limited
|
17
|
-
# subset of the ONIX specification, but the core attributes are there. More will be
|
18
|
-
# added over time.
|
19
|
-
#
|
20
|
-
# = Usage
|
21
|
-
#
|
22
|
-
# == Loading from an REXML document
|
23
|
-
#
|
24
|
-
# require 'rubygems'
|
25
|
-
# require 'rbook/onix'
|
26
|
-
# file = File.open("./onix_message.xml", "r")
|
27
|
-
# doc = REXML::Document.new(file)
|
28
|
-
# msg = Onix::Message.load_from_xmldoc(doc)
|
29
|
-
#
|
30
|
-
# puts msg.from_company
|
31
|
-
#
|
32
|
-
# == Creation
|
33
|
-
#
|
34
|
-
# require 'rubygems'
|
35
|
-
# require 'rbook/onix'
|
36
|
-
# msg = RBook::Onix::Message.new
|
37
|
-
# msg.from_company = 'XYZ Books'
|
38
|
-
# msg.from_name = 'Joe Blogs'
|
39
|
-
# msg.message_note = "A sample ONIX file"
|
40
|
-
#
|
41
|
-
# product = RBook::Onix::Product.new
|
42
|
-
# product.product_identifier = "020161622X"
|
43
|
-
# product.title = "Pragmatic Programmer"
|
44
|
-
# product.subtitle = "From Journeyman to Master"
|
45
|
-
# product.form = "BB"
|
46
|
-
# product.description = "A book about programming and stuff"
|
47
|
-
#
|
48
|
-
# contributor1 = RBook::Onix::Contributor.new
|
49
|
-
# contributor1.name_inverted = "Hunt, Andrew"
|
50
|
-
# contributor1.role = "A01"
|
51
|
-
# contributor1.sequence = "01"
|
52
|
-
# contributor2 = RBook::Onix::Contributor.new
|
53
|
-
# contributor2.name_inverted = "Thomas, David"
|
54
|
-
# contributor2.role = "A01"
|
55
|
-
# contributor2.sequence = "02"
|
56
|
-
# product.add_contributor(contributor1)
|
57
|
-
# product.add_contributor(contributor2)
|
58
|
-
#
|
59
|
-
# supply_detail = RBook::Onix::SupplyDetail.new
|
60
|
-
# supply_detail.supplier_name = "Rainbow Book Agencies"
|
61
|
-
# supply_detail.price = BigDecimal.new(29.95)
|
62
|
-
# supply_detail.availability = "CS"
|
63
|
-
# product.add_supply_detail(supply_detail)
|
64
|
-
#
|
65
|
-
# msg.add_product(product)
|
66
|
-
# puts msg.to_s
|
67
|
-
module Onix
|
68
|
-
|
69
|
-
end
|
70
|
-
end
|
@@ -1,60 +0,0 @@
|
|
1
|
-
require 'rexml/document'
|
2
|
-
require 'rubygems'
|
3
|
-
|
4
|
-
module RBook
|
5
|
-
module Onix
|
6
|
-
|
7
|
-
class Contributor
|
8
|
-
attr_accessor :sequence_number, :role, :name, :name_inverted
|
9
|
-
|
10
|
-
# Attempts to create a contributor object using the supplied xml element
|
11
|
-
def Contributor.load_from_element(element)
|
12
|
-
raise ArgumentError, 'load_from_element expects a REXML element object' unless element.class == REXML::Element
|
13
|
-
|
14
|
-
if REXML::XPath.first(element, '//Contributor').nil?
|
15
|
-
raise LoadError, 'supplied REXML document object does not appear contain a valid contributor fragment'
|
16
|
-
end
|
17
|
-
|
18
|
-
contributor = Contributor.new
|
19
|
-
|
20
|
-
tmp = REXML::XPath.first(element, '//Contributor/SequenceNumber')
|
21
|
-
contributor.sequence_number = tmp.text if tmp != nil
|
22
|
-
|
23
|
-
tmp = REXML::XPath.first(element, '//Contributor/ContributorRole')
|
24
|
-
contributor.role = tmp.text if tmp != nil
|
25
|
-
|
26
|
-
tmp = REXML::XPath.first(element, '//Contributor/PersonName')
|
27
|
-
contributor.name = tmp.text if tmp != nil
|
28
|
-
|
29
|
-
tmp = REXML::XPath.first(element, '//Contributor/PersonNameInverted')
|
30
|
-
contributor.name_inverted = tmp.text if tmp != nil
|
31
|
-
|
32
|
-
return contributor
|
33
|
-
|
34
|
-
end
|
35
|
-
|
36
|
-
# Return an xml element representing this contributor
|
37
|
-
def to_element
|
38
|
-
raise 'Contributor must have a sequence number to create an element' if @sequence_number.nil?
|
39
|
-
raise 'Contributor must have a role to create an element' if @role.nil?
|
40
|
-
raise '' if @name_inverted.nil? && @name.nil?
|
41
|
-
|
42
|
-
contributor = REXML::Element.new('Contributor')
|
43
|
-
contributor.add_element('SequenceNumber').text = self.sequence_number
|
44
|
-
contributor.add_element('ContributorRole').text = self.role.to_xs
|
45
|
-
contributor.add_element('PersonName').text = name.to_xs unless self.name.nil?
|
46
|
-
contributor.add_element('PersonNameInverted').text = self.name_inverted.to_xs unless self.name_inverted.nil?
|
47
|
-
|
48
|
-
return contributor
|
49
|
-
end
|
50
|
-
|
51
|
-
# Return an XML string representing this contributor
|
52
|
-
def to_s
|
53
|
-
tmp = to_element
|
54
|
-
output = ''
|
55
|
-
tmp.write(output, 0)
|
56
|
-
return output
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
data/lib/rbook/onix/lists.rb
DELETED
@@ -1,100 +0,0 @@
|
|
1
|
-
module RBook
|
2
|
-
module Onix
|
3
|
-
module Lists
|
4
|
-
|
5
|
-
FORM_CODES = [
|
6
|
-
['Undefined', '00'],
|
7
|
-
['Audio', 'AA'],
|
8
|
-
['Audio - Cassette', 'AB'],
|
9
|
-
['Audio - CD', 'AC'],
|
10
|
-
['Audio - DAT', 'AD'],
|
11
|
-
['Audio - Disk', 'AE'],
|
12
|
-
['Audio - Tape', 'AF'],
|
13
|
-
['Audio - Other', 'AZ'],
|
14
|
-
['Book', 'BA'],
|
15
|
-
['Book - Hardback', 'BB'],
|
16
|
-
['Book - Paperback', 'BC'],
|
17
|
-
['Book - Loose-leaf', 'BD'],
|
18
|
-
['Book - Spiral Bound', 'BE'],
|
19
|
-
['Book - Pamphlet', 'BF'],
|
20
|
-
['Book - Leather / Fine Binding', 'BG'],
|
21
|
-
['Book - Board', 'BH'],
|
22
|
-
['Book - Rag', 'BI'],
|
23
|
-
['Book - Bath', 'BJ'],
|
24
|
-
['Book - Other', 'BZ'],
|
25
|
-
['Cartographic - Sheet Map', 'CA'],
|
26
|
-
['Cartographic - Sheet Map, Folded', 'CB'],
|
27
|
-
['Cartographic - Sheet Map, Flat', 'CC'],
|
28
|
-
['Cartographic - Sheet Map, Rolled', 'CD'],
|
29
|
-
['Cartographic - Globe', 'CE'],
|
30
|
-
['Cartographic - Other', 'CZ'],
|
31
|
-
['Digital', 'DA'],
|
32
|
-
['Digital - CDROM', 'DB'],
|
33
|
-
['Digital - CD-Interactive', 'DC'],
|
34
|
-
['Digital - DVD', 'DD'],
|
35
|
-
['Digital - Game Cartridge', 'DE'],
|
36
|
-
['Digital - Diskette', 'DF'],
|
37
|
-
['Digital - Electronic Book Text', 'DG'],
|
38
|
-
['Digital - Online File', 'DH'],
|
39
|
-
['Digital - Other', 'DZ'],
|
40
|
-
['Film or Transparency', 'FA'],
|
41
|
-
['Film', 'FB'],
|
42
|
-
['Film - Slides', 'FC'],
|
43
|
-
['Film - OHP Transparencies', 'FD'],
|
44
|
-
['Film - Other ', 'FZ'],
|
45
|
-
['Microform', 'MA'],
|
46
|
-
['Microform - Microfiche', 'MB'],
|
47
|
-
['Microform - Microfilm', 'MC'],
|
48
|
-
['Microform - Other', 'MZ'],
|
49
|
-
['Print - Misc', 'PA'],
|
50
|
-
['Print - Address Book', 'PB'],
|
51
|
-
['Print - Calendar', 'PC'],
|
52
|
-
['Print - Cards', 'PD'],
|
53
|
-
['Print - Copymasters', 'PE'],
|
54
|
-
['Print - Diary', 'PF'],
|
55
|
-
['Print - Frieze', 'PG'],
|
56
|
-
['Print - Kit', 'PH'],
|
57
|
-
['Print - Sheet Music', 'PI'],
|
58
|
-
['Print - Postcard Book or Pack', 'PJ'],
|
59
|
-
['Print - Poster', 'PK'],
|
60
|
-
['Print - Record Book', 'PL'],
|
61
|
-
['Print - Wallet', 'PM'],
|
62
|
-
['Print - Pictures or Photographs', 'PN'],
|
63
|
-
['Print - Wallchart', 'PO'],
|
64
|
-
['Print - Other', 'PZ'],
|
65
|
-
['Video', 'VA'],
|
66
|
-
['Video - VHS, PAL', 'VB'],
|
67
|
-
['Video - VHA, NTSC', 'VC'],
|
68
|
-
['Video - Betamax, PAL', 'VD'],
|
69
|
-
['Video - Betamax, NTSC', 'VE'],
|
70
|
-
['Video - disk', 'VF'],
|
71
|
-
['Video - VHS, SECAM', 'VG'],
|
72
|
-
['Video - Betamax, SECAM', 'VH'],
|
73
|
-
['Video - Other Format','VZ'],
|
74
|
-
['Multiple - Mixed Media Product', 'WW'],
|
75
|
-
['Misc - Quantity Pack', 'WX'],
|
76
|
-
['Misc - Trade-only Material', 'XA'],
|
77
|
-
['Misc - Dumpbim - Empty', 'XB'],
|
78
|
-
['Misc - Dumpbin - Filled', 'XC'],
|
79
|
-
['Misc - Counterpack - Empty', 'XD'],
|
80
|
-
['Misc - Counterpack - Filled', 'XE'],
|
81
|
-
['Misc - Poster', 'XF'],
|
82
|
-
['Misc - Shelf Strip', 'XG'],
|
83
|
-
['Misc - Window Piece', 'XH'],
|
84
|
-
['Misc - Streamer', 'XI'],
|
85
|
-
['Misc - Spinner', 'XJ'],
|
86
|
-
['Misc - Large Book Display', 'XK'],
|
87
|
-
['Misc - Shrink Wrapped Pack', 'XL'],
|
88
|
-
['Misc - Other Point of Sale', 'XZ'],
|
89
|
-
['General Merchandise', 'ZA'],
|
90
|
-
['Misc - Doll', 'ZB'],
|
91
|
-
['Misc - Soft Toy', 'ZC'],
|
92
|
-
['Misc - Toy', 'ZD'],
|
93
|
-
['Misc - Game', 'ZE'],
|
94
|
-
['Misc - T-shirt', 'ZF'],
|
95
|
-
['Misc - Other Merchandise', 'ZZ'],
|
96
|
-
].freeze
|
97
|
-
|
98
|
-
end
|
99
|
-
end
|
100
|
-
end
|
data/lib/rbook/onix/message.rb
DELETED
@@ -1,112 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'rexml/document'
|
3
|
-
|
4
|
-
module RBook
|
5
|
-
module Onix
|
6
|
-
|
7
|
-
class Message
|
8
|
-
attr_reader :products
|
9
|
-
attr_accessor :from_company, :from_person, :from_email, :message_note, :sent_date, :to_person, :to_company
|
10
|
-
|
11
|
-
VERSION = 0.1
|
12
|
-
ONIX_DTD_URL = "http://www.editeur.org/onix/2.1/reference/onix-international.dtd"
|
13
|
-
|
14
|
-
def initialize
|
15
|
-
@products = []
|
16
|
-
end
|
17
|
-
|
18
|
-
# Attempts to create a message object using thge supplied xml string
|
19
|
-
def self.load_from_string(str)
|
20
|
-
doc = REXML::Document.new(str)
|
21
|
-
self.load_from_xmldoc(doc)
|
22
|
-
end
|
23
|
-
|
24
|
-
# Attempts to create a message object using thge supplied xml document
|
25
|
-
def self.load_from_xmldoc(doc)
|
26
|
-
raise ArgumentError, 'load_from_xmldoc expects a REXML document object' unless doc.class == REXML::Document
|
27
|
-
if REXML::XPath.first(doc, '/ONIXMessage/').nil? ||
|
28
|
-
REXML::XPath.first(doc, '/ONIXMessage/Header').nil? ||
|
29
|
-
REXML::XPath.first(doc, '/ONIXMessage/Product').nil?
|
30
|
-
raise LoadError, 'supplied REXML document object does not appear to be a valid ONIX file'
|
31
|
-
end
|
32
|
-
|
33
|
-
msg = Onix::Message.new
|
34
|
-
|
35
|
-
tmpelement = REXML::XPath.first(doc, '/ONIXMessage/Header/FromCompany')
|
36
|
-
msg.from_company = tmpelement.text if tmpelement != nil
|
37
|
-
|
38
|
-
tmpelement = REXML::XPath.first(doc, '/ONIXMessage/Header/FromPerson')
|
39
|
-
msg.from_person = tmpelement.text if tmpelement != nil
|
40
|
-
|
41
|
-
tmpelement = REXML::XPath.first(doc, '/ONIXMessage/Header/FromEmail')
|
42
|
-
msg.from_email = tmpelement.text if tmpelement != nil
|
43
|
-
|
44
|
-
tmpelement = REXML::XPath.first(doc, '/ONIXMessage/Header/SentDate')
|
45
|
-
tmpdate = Date.civil(tmpelement.text[0,4].to_i, tmpelement.text[4,2].to_i, tmpelement.text[6,2].to_i) if tmpelement != nil
|
46
|
-
msg.sent_date = tmpdate if tmpdate != nil
|
47
|
-
|
48
|
-
tmpelement = REXML::XPath.first(doc, '/ONIXMessage/Header/ToCompany')
|
49
|
-
msg.to_company = tmpelement.text if tmpelement != nil
|
50
|
-
|
51
|
-
tmpelement = REXML::XPath.first(doc, '/ONIXMessage/Header/ToPerson')
|
52
|
-
msg.to_person = tmpelement.text if tmpelement != nil
|
53
|
-
|
54
|
-
products = REXML::XPath.each(doc, '/ONIXMessage/Product') { |product|
|
55
|
-
msg.add_product(Onix::Product.load_from_element(product))
|
56
|
-
}
|
57
|
-
|
58
|
-
return msg
|
59
|
-
end
|
60
|
-
|
61
|
-
# Adds a new product to this message
|
62
|
-
def add_product(product)
|
63
|
-
raise ArgumentError, 'Argument must be a Onix::Product' if product.class != Onix::Product
|
64
|
-
@products << product
|
65
|
-
end
|
66
|
-
|
67
|
-
# Returns an XML string representing this message
|
68
|
-
def to_s
|
69
|
-
doc = to_xml
|
70
|
-
output = ''
|
71
|
-
doc.write(output, 0)
|
72
|
-
return output
|
73
|
-
end
|
74
|
-
|
75
|
-
def header
|
76
|
-
raise 'from_compnay must be set to create an onix message' if from_company == nil
|
77
|
-
raise 'from_person must be set to create an onix message' if from_person == nil
|
78
|
-
|
79
|
-
header = REXML::Element.new('Header')
|
80
|
-
header.add_element('FromCompany').text = from_company.to_xs
|
81
|
-
header.add_element('FromPerson').text = from_person.to_xs
|
82
|
-
header.add_element('FromEmail').text = from_email.to_xs unless from_email.nil?
|
83
|
-
header.add_element('MessageNote').text = message_note.to_xs unless message_note.nil?
|
84
|
-
header.add_element('ToCompany').text = to_company.to_xs unless to_company.nil?
|
85
|
-
header.add_element('ToPerson').text = to_person.to_xs unless to_person.nil?
|
86
|
-
|
87
|
-
now = Time.now
|
88
|
-
header.add_element('SentDate').text = "%.4d%.2d%.2d" % [ now.year, now.month, now.day ]
|
89
|
-
return header
|
90
|
-
end
|
91
|
-
|
92
|
-
# Returns an XML document representing this message
|
93
|
-
def to_xml
|
94
|
-
raise 'There must be at least 1 product to burn' if @products.size < 1
|
95
|
-
|
96
|
-
doc = REXML::Document.new
|
97
|
-
doc << REXML::XMLDecl.new
|
98
|
-
doc << REXML::DocType.new('ONIXMessage', "SYSTEM \"#{ONIX_DTD_URL}\"")
|
99
|
-
msg = doc.add_element('ONIXMessage')
|
100
|
-
msg.add_element(header)
|
101
|
-
|
102
|
-
@products.each do |product|
|
103
|
-
prod = msg.add_element(product.to_element)
|
104
|
-
end
|
105
|
-
|
106
|
-
return doc
|
107
|
-
end
|
108
|
-
|
109
|
-
end
|
110
|
-
|
111
|
-
end
|
112
|
-
end
|
data/lib/rbook/onix/product.rb
DELETED
@@ -1,189 +0,0 @@
|
|
1
|
-
require 'rexml/document'
|
2
|
-
require 'rubygems'
|
3
|
-
|
4
|
-
module RBook
|
5
|
-
module Onix
|
6
|
-
class Product
|
7
|
-
|
8
|
-
attr_accessor :record_reference, :notification_type, :product_identifier, :title, :subtitle, :pages, :publication_date, :price, :description, :form, :bicmainsubject, :publisher, :supplier, :website, :edition
|
9
|
-
attr_reader :contributors, :sales_restrictions, :supply_details
|
10
|
-
|
11
|
-
def initialize
|
12
|
-
@contributors = []
|
13
|
-
@supply_details = []
|
14
|
-
@sales_restrictions = []
|
15
|
-
end
|
16
|
-
|
17
|
-
# Attempts to create a product object using the supplied xml element
|
18
|
-
def Product.load_from_element(element)
|
19
|
-
raise ArgumentError, 'load_from_element expects a REXML element object' unless element.class == REXML::Element
|
20
|
-
|
21
|
-
if REXML::XPath.first(element, '//Product').nil?
|
22
|
-
raise LoadError, 'supplied REXML document object does not appear contain a valid product fragment'
|
23
|
-
end
|
24
|
-
|
25
|
-
product = Product.new
|
26
|
-
|
27
|
-
tmp = REXML::XPath.first(element, '//Product/RecordReference')
|
28
|
-
product.record_reference = tmp.text if tmp != nil
|
29
|
-
|
30
|
-
tmp = REXML::XPath.first(element, '//Product/NotificationType')
|
31
|
-
product.notification_type = tmp.text if tmp != nil
|
32
|
-
|
33
|
-
tmp = REXML::XPath.first(element, '//Product/ProductIdentifier/IDValue')
|
34
|
-
product.product_identifier = tmp.text if tmp != nil
|
35
|
-
|
36
|
-
tmp = REXML::XPath.first(element, '//Product/ProductForm')
|
37
|
-
product.form = tmp.text if tmp != nil
|
38
|
-
|
39
|
-
tmp = REXML::XPath.first(element, '//Product/NumberOfPages')
|
40
|
-
product.pages = tmp.text if tmp != nil
|
41
|
-
|
42
|
-
tmp = REXML::XPath.first(element, '//Product/BICMainSubject')
|
43
|
-
product.bicmainsubject = tmp.text if tmp != nil
|
44
|
-
|
45
|
-
tmp = REXML::XPath.first(element, '//Product/DistinctiveTitle')
|
46
|
-
if !tmp.nil?
|
47
|
-
product.title = tmp.text
|
48
|
-
tmp = REXML::XPath.first(element, '//Product/Subtitle') if !tmp.nil?
|
49
|
-
product.subtitle = tmp.text
|
50
|
-
else
|
51
|
-
tmp = REXML::XPath.first(element, '//Product/Title/TitleText')
|
52
|
-
product.title = tmp.text unless tmp.nil?
|
53
|
-
tmp = REXML::XPath.first(element, '//Product/Title/Subtitle')
|
54
|
-
product.subtitle = tmp.text unless tmp.nil?
|
55
|
-
end
|
56
|
-
|
57
|
-
tmp = REXML::XPath.first(element, '//Product/EditionNumber')
|
58
|
-
product.edition = tmp.text if tmp != nil
|
59
|
-
|
60
|
-
tmp = REXML::XPath.first(element, '//Product/PublicationDate')
|
61
|
-
tmpdate = Date.civil(tmp.text[0,4].to_i, tmp.text[4,2].to_i, tmp.text[6,2].to_i) if tmp != nil
|
62
|
-
product.publication_date = tmpdate if tmpdate != nil
|
63
|
-
|
64
|
-
tmp = REXML::XPath.first(element, '//Product/Publisher/PublisherName')
|
65
|
-
product.publisher = tmp.text if tmp != nil
|
66
|
-
|
67
|
-
REXML::XPath.each(element, '//Product/Contributor') { |contributor|
|
68
|
-
product.add_contributor(Onix::Contributor.load_from_element(contributor))
|
69
|
-
}
|
70
|
-
|
71
|
-
REXML::XPath.each(element, '//Product/SupplyDetail') { |detail|
|
72
|
-
product.add_supply_detail(Onix::SupplyDetail.load_from_element(detail))
|
73
|
-
}
|
74
|
-
|
75
|
-
return product
|
76
|
-
end
|
77
|
-
|
78
|
-
# Add a new contributor to this product
|
79
|
-
def add_contributor(newAuthor)
|
80
|
-
raise ArgumentError, 'Argument to add_contributor must be an ONIX::Contributor' if newAuthor.class != Contributor
|
81
|
-
@contributors << newAuthor
|
82
|
-
end
|
83
|
-
|
84
|
-
# Add a new contributor to this product
|
85
|
-
def add_sales_restriction(restriction)
|
86
|
-
raise ArgumentError, 'Argument to add_sales_restriction must be an ONIX::SalesRestriction' if restriction.class != SalesRestriction
|
87
|
-
@sales_restrictions << restriction
|
88
|
-
end
|
89
|
-
|
90
|
-
# Add a new contributor to this product
|
91
|
-
def add_supply_detail(detail)
|
92
|
-
raise ArgumentError, 'Argument to add_supply_detail must be an ONIX::SupplyDetail' if detail.class != SupplyDetail
|
93
|
-
@supply_details << detail
|
94
|
-
end
|
95
|
-
|
96
|
-
# Return an xml element representing this contributor
|
97
|
-
def to_element
|
98
|
-
raise 'product_identifier must be set' if self.product_identifier.nil?
|
99
|
-
|
100
|
-
product = REXML::Element.new('Product')
|
101
|
-
|
102
|
-
if self.record_reference
|
103
|
-
product.add_element('RecordReference').text = self.record_reference
|
104
|
-
else
|
105
|
-
product.add_element('RecordReference').text = self.product_identifier
|
106
|
-
end
|
107
|
-
|
108
|
-
product.add_element('NotificationType').text = '03'
|
109
|
-
|
110
|
-
product_identifier = REXML::Element.new('ProductIdentifier')
|
111
|
-
if ISBN::valid_isbn13?(self.product_identifier)
|
112
|
-
product_identifier.add_element('ProductIDType').text = '03'
|
113
|
-
elsif ISBN::valid_isbn10?(self.product_identifier)
|
114
|
-
product_identifier.add_element('ProductIDType').text = '02'
|
115
|
-
else
|
116
|
-
product_identifier.add_element('ProductIDType').text = '01'
|
117
|
-
end
|
118
|
-
product_identifier.add_element('IDValue').text = self.product_identifier.to_xs
|
119
|
-
product.add_element(product_identifier)
|
120
|
-
|
121
|
-
if form != nil
|
122
|
-
product.add_element('ProductForm').text = self.form.to_xs
|
123
|
-
end
|
124
|
-
|
125
|
-
product.add_element('NoSeries')
|
126
|
-
|
127
|
-
title = REXML::Element.new('Title')
|
128
|
-
title.add_element('TitleType').text = '01'
|
129
|
-
title.add_element('TitleText').text = self.title.to_xs unless self.title.nil?
|
130
|
-
title.add_element('Subtitle').text = self.subtitle.to_xs unless self.subtitle.nil?
|
131
|
-
product.add_element(title)
|
132
|
-
|
133
|
-
if website != nil
|
134
|
-
product_website = REXML::Element.new('Website')
|
135
|
-
product_website.add_element('WebsiteLink').text = self.website.to_xs
|
136
|
-
product.add_element(product_website)
|
137
|
-
end
|
138
|
-
|
139
|
-
contributors.each do |contributor|
|
140
|
-
product.add_element(contributor.to_element)
|
141
|
-
end
|
142
|
-
|
143
|
-
product.add_element('NoEdition')
|
144
|
-
|
145
|
-
product.add_element('NumberOfPages').text = self.pages.to_s unless self.pages.nil?
|
146
|
-
|
147
|
-
if bicmainsubject != nil
|
148
|
-
product.add_element('BICMainSubject').text = self.bicmainsubject.to_xs
|
149
|
-
end
|
150
|
-
|
151
|
-
if description != nil
|
152
|
-
other_text = REXML::Element.new('OtherText')
|
153
|
-
other_text.add_element('TextTypeCode').text = '01'
|
154
|
-
other_text.add_element('Text').text = self.description.to_xs
|
155
|
-
product.add_element(other_text)
|
156
|
-
end
|
157
|
-
|
158
|
-
if publisher != nil
|
159
|
-
publisher = REXML::Element.new('Publisher')
|
160
|
-
publisher.add_element('PublishingRole').text = '01'
|
161
|
-
publisher.add_element('PublisherName').text = self.publisher.to_xs
|
162
|
-
product.add_element(publisher)
|
163
|
-
end
|
164
|
-
|
165
|
-
supply_details.each do |detail|
|
166
|
-
product.add_element(detail.to_element)
|
167
|
-
end
|
168
|
-
|
169
|
-
sales_restrictions.each do |restriction|
|
170
|
-
product.add_element(restriction.to_element)
|
171
|
-
end
|
172
|
-
|
173
|
-
if publication_date != nil
|
174
|
-
product.add_element('PublicationDate').text = "%.4d%.2d%.2d" % [ publication_date.year, publication_date.month, publication_date.day ]
|
175
|
-
end
|
176
|
-
|
177
|
-
return product
|
178
|
-
end
|
179
|
-
|
180
|
-
# return an XML string representing this contributor
|
181
|
-
def to_s
|
182
|
-
output = ''
|
183
|
-
to_element.write(output, 0)
|
184
|
-
return output
|
185
|
-
end
|
186
|
-
end
|
187
|
-
|
188
|
-
end
|
189
|
-
end
|