rbook-bisac 0.5 → 0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +1 -1
- data/lib/rbook/bisac/po.rb +23 -3
- data/lib/rbook/bisac/po_line_item.rb +6 -1
- data/specs/data/bisac_multi_po.txt +41 -0
- data/specs/new_po_line_item_spec.rb +8 -0
- data/specs/new_po_spec.rb +21 -3
- metadata +10 -10
- data/specs/data/bisac_po.bsc +0 -112
data/Rakefile
CHANGED
data/lib/rbook/bisac/po.rb
CHANGED
@@ -23,12 +23,32 @@ module RBook
|
|
23
23
|
# reads a bisac text file into memory. input should be a string
|
24
24
|
# that specifies the file path
|
25
25
|
def self.load_from_file(input)
|
26
|
+
$stderr.puts "WARNING: RBook::Bisac::PO.load_from_file is deprecated. It only returns the first PO in the file. use parse_file instead."
|
27
|
+
self.parse_file(input) { |msg| return msg }
|
28
|
+
return nil
|
29
|
+
end
|
30
|
+
|
31
|
+
# return all POs from a BISAC file
|
32
|
+
def self.parse_file(input, &block)
|
33
|
+
raise ArgumentError, 'no file provided' if input.nil?
|
26
34
|
raise RBook::InvalidFileError, 'Invalid file' unless File.exist?(input)
|
27
35
|
data = []
|
28
|
-
File.open(input) do |f|
|
29
|
-
f.each_line
|
36
|
+
File.open(input, "r") do |f|
|
37
|
+
f.each_line do |l|
|
38
|
+
data << l
|
39
|
+
|
40
|
+
# yield each message found in the file. A line starting with
|
41
|
+
# 90 is the footer to a PO
|
42
|
+
if data.last[0,2] == "90"
|
43
|
+
yield self.build_message(data)
|
44
|
+
data = []
|
45
|
+
end
|
46
|
+
end
|
30
47
|
end
|
31
|
-
|
48
|
+
|
49
|
+
# if we've got to the end of the file, and haven't hit a footer line yet, the file
|
50
|
+
# is probably malformed. Call build_message anyway, and let it detect any errors
|
51
|
+
yield self.build_message(data) if data.size > 0
|
32
52
|
end
|
33
53
|
|
34
54
|
# creates a RBook::Bisac::PO object from a string. Input should
|
@@ -22,7 +22,12 @@ module RBook
|
|
22
22
|
item.sequence_number = data[2,5].to_i
|
23
23
|
item.po_number = data[7,13].strip
|
24
24
|
item.line_item_number = data[21,10].strip
|
25
|
-
|
25
|
+
|
26
|
+
# prefer the 13 digit ISBN if it exists (it's a non-standard, Pacstream extension)
|
27
|
+
# fallback to the ISBN10
|
28
|
+
item.isbn = data[80,13]
|
29
|
+
item.isbn ||= data[31,10]
|
30
|
+
item.isbn.strip!
|
26
31
|
item.qty = data[41,5].to_i
|
27
32
|
item.catalogue_code = data[46,1].strip
|
28
33
|
item.price = BigDecimal.new(data[47,6])
|
@@ -0,0 +1,41 @@
|
|
1
|
+
0000001901375X .Pauline Book071126INTERNET.BSC F039013725
|
2
|
+
1000002 13349 901375X 9013725 071126000000Y 000000001N00020000000
|
3
|
+
4000003 13349 Y000000000108264734150000100000000000000000000400000000
|
4
|
+
4100004 13349 Teresa of Avila
|
5
|
+
4200005 13349 WILLIAMS ROWAN
|
6
|
+
5000006 13349 0000500000000010000000001
|
7
|
+
90000070000000000001000010000000001000010000100000000000000100001000000000000000
|
8
|
+
0000001901375X .Pauline Book071128INTERNET.BSC F039013725
|
9
|
+
1000002 13366 901375X 9013725 071128000000Y 000000001N00020000000
|
10
|
+
4000003 13366 Y000000000106872781470000100000000000000000000400000000
|
11
|
+
4100004 13366 New Interpreters Bible VOL 1
|
12
|
+
4200005 13366 NIB
|
13
|
+
4000006 13366 Y000000000206872781550000100000000000000000000400000000
|
14
|
+
4100007 13366 New Interpreters Bible VOL 2
|
15
|
+
4200008 13366 NIB
|
16
|
+
4000009 13366 Y000000000306872781630000100000000000000000000400000000
|
17
|
+
4100010 13366 New Interpreters Bible VOL 3
|
18
|
+
4200011 13366 NIB
|
19
|
+
4000012 13366 Y000000000406872781710000100000000000000000000400000000
|
20
|
+
4100013 13366 New Interpreters Bible VOL 4
|
21
|
+
4200014 13366 NIB
|
22
|
+
4000015 13366 Y0000000005068727818X0000200000000000000000000400000000
|
23
|
+
4100016 13366 New Interpreters Bible VOL 5
|
24
|
+
4200017 13366 NIB
|
25
|
+
4000018 13366 Y000000000606872781980000100000000000000000000400000000
|
26
|
+
4100019 13366 New Interpreters Bible VOL 6
|
27
|
+
4200020 13366 NIB
|
28
|
+
4000021 13366 Y000000000706872782010000100000000000000000000400000000
|
29
|
+
4100022 13366 New Interpreters Bible VOL 7
|
30
|
+
4200023 13366 NIB
|
31
|
+
4000024 13366 Y000000000806872782280000100000000000000000000400000000
|
32
|
+
4100025 13366 New Interpreters Bible VOL 9
|
33
|
+
4200026 13366 NIB
|
34
|
+
4000027 13366 Y000000000906872782360000100000000000000000000400000000
|
35
|
+
4100028 13366 New Interpreters Bible VOL 10
|
36
|
+
4200029 13366 NIB
|
37
|
+
4000030 13366 Y000000001006872782440000100000000000000000000400000000
|
38
|
+
4100031 13366 New Interpreters Bible VOL 11
|
39
|
+
4200032 13366 NIB
|
40
|
+
5000033 13366 0003200000000100000000011
|
41
|
+
90000340000000000010000010000000011000010000100000000000001000001000000000000000
|
@@ -7,6 +7,7 @@ context "A new bisac purchase order line item object" do
|
|
7
7
|
|
8
8
|
setup do
|
9
9
|
@valid_row = "4000003 14976 Y000000000102978513220000100000000000000000000550000000"
|
10
|
+
@valid_isbn13_row = "4000003 14627 Y000000000103855198500000600000000000000000000400000000 9780385519854"
|
10
11
|
@invalid_row_nil = nil
|
11
12
|
@invalid_row_num = 23
|
12
13
|
end
|
@@ -24,6 +25,13 @@ context "A new bisac purchase order line item object" do
|
|
24
25
|
item.price.should eql(0)
|
25
26
|
end
|
26
27
|
|
28
|
+
specify "Should prefer the ISBN13 over ISBN10 when available" do
|
29
|
+
item = RBook::Bisac::POLineItem.load_from_string(@valid_isbn13_row)
|
30
|
+
item.should be_a_kind_of(RBook::Bisac::POLineItem)
|
31
|
+
|
32
|
+
item.isbn.should eql("9780385519854")
|
33
|
+
end
|
34
|
+
|
27
35
|
specify "Should raise an appropriate exception when an invalid file is loaded" do
|
28
36
|
lambda { item = RBook::Bisac::POLineItem.load_from_string(@invalid_row_nil) }.should raise_error(RBook::InvalidArgumentError)
|
29
37
|
lambda { item = RBook::Bisac::POLineItem.load_from_string(@invalid_row_num) }.should raise_error(RBook::InvalidArgumentError)
|
data/specs/new_po_spec.rb
CHANGED
@@ -7,11 +7,29 @@ context "A new bisac purchase order object" do
|
|
7
7
|
|
8
8
|
setup do
|
9
9
|
@valid_file = File.dirname(__FILE__) + "/data/bisac_po.txt"
|
10
|
+
@valid_multi_file = File.dirname(__FILE__) + "/data/bisac_multi_po.txt"
|
10
11
|
@invalid_file_no_header = File.dirname(__FILE__) + "/data/bisac_po_no_header.txt"
|
11
12
|
@invalid_file_no_footer = File.dirname(__FILE__) + "/data/bisac_po_no_footer.txt"
|
12
13
|
@invalid_file_onix = File.dirname(__FILE__) + "/data/single_product.xml"
|
13
14
|
end
|
14
15
|
|
16
|
+
specify "Should load multiple POs from a single file correctly" do
|
17
|
+
pos = []
|
18
|
+
RBook::Bisac::PO.parse_file(@valid_multi_file) { |po| pos << po }
|
19
|
+
|
20
|
+
pos.size.should eql(2)
|
21
|
+
|
22
|
+
pos[0].should be_a_kind_of(RBook::Bisac::PO)
|
23
|
+
pos[0].items.size.should eql(1)
|
24
|
+
pos[0].source_name.should eql(".Pauline Book")
|
25
|
+
pos[0].po_number.should eql("13349")
|
26
|
+
|
27
|
+
pos[1].should be_a_kind_of(RBook::Bisac::PO)
|
28
|
+
pos[1].items.size.should eql(10)
|
29
|
+
pos[1].source_name.should eql(".Pauline Book")
|
30
|
+
pos[1].po_number.should eql("13366")
|
31
|
+
end
|
32
|
+
|
15
33
|
specify "Should load a valid BISAC PO file from disk correctly" do
|
16
34
|
msg = RBook::Bisac::PO.load_from_file(@valid_file)
|
17
35
|
msg.should be_a_kind_of(RBook::Bisac::PO)
|
@@ -59,8 +77,8 @@ context "A new bisac purchase order object" do
|
|
59
77
|
end
|
60
78
|
|
61
79
|
specify "Should raise an appropriate exception when an invalid file is loaded" do
|
62
|
-
lambda { msg = RBook::Bisac::PO.
|
63
|
-
lambda { msg = RBook::Bisac::PO.
|
64
|
-
lambda { msg = RBook::Bisac::PO.
|
80
|
+
lambda { msg = RBook::Bisac::PO.parse_file(@invalid_file_no_header) }.should raise_error(RBook::InvalidFileError)
|
81
|
+
lambda { msg = RBook::Bisac::PO.parse_file(@invalid_file_no_footer) }.should raise_error(RBook::InvalidFileError)
|
82
|
+
lambda { msg = RBook::Bisac::PO.parse_file(@invalid_file_onix) }.should raise_error(RBook::InvalidFileError)
|
65
83
|
end
|
66
84
|
end
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.4
|
|
3
3
|
specification_version: 1
|
4
4
|
name: rbook-bisac
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: "0.
|
7
|
-
date: 2007-
|
6
|
+
version: "0.6"
|
7
|
+
date: 2007-12-10 00:00:00 +11:00
|
8
8
|
summary: A library for manipulating BISAC files
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -30,30 +30,30 @@ authors:
|
|
30
30
|
- James Healy
|
31
31
|
files:
|
32
32
|
- lib/rbook
|
33
|
+
- lib/rbook/bisac.rb
|
33
34
|
- lib/rbook/bisac
|
35
|
+
- lib/rbook/bisac/message.rb
|
34
36
|
- lib/rbook/bisac/po.rb
|
35
|
-
- lib/rbook/bisac/product.rb
|
36
37
|
- lib/rbook/bisac/po_line_item.rb
|
37
|
-
- lib/rbook/bisac/
|
38
|
-
- lib/rbook/bisac.rb
|
38
|
+
- lib/rbook/bisac/product.rb
|
39
39
|
- lib/rbook/errors.rb
|
40
40
|
- specs/data
|
41
|
-
- specs/data/bisac_po_no_header.txt
|
42
|
-
- specs/data/bisac_po_no_footer.txt
|
43
41
|
- specs/data/bisac_po.txt
|
42
|
+
- specs/data/bisac_po_no_footer.txt
|
43
|
+
- specs/data/bisac_po_no_header.txt
|
44
44
|
- specs/data/valid_bisac.txt
|
45
|
-
- specs/data/
|
46
|
-
- specs/new_po_spec.rb
|
45
|
+
- specs/data/bisac_multi_po.txt
|
47
46
|
- specs/new_bisac_spec.rb
|
48
47
|
- specs/new_po_line_item_spec.rb
|
48
|
+
- specs/new_po_spec.rb
|
49
49
|
- Rakefile
|
50
50
|
- README
|
51
51
|
- COPYING
|
52
52
|
- LICENSE
|
53
53
|
test_files:
|
54
|
-
- specs/new_po_spec.rb
|
55
54
|
- specs/new_bisac_spec.rb
|
56
55
|
- specs/new_po_line_item_spec.rb
|
56
|
+
- specs/new_po_spec.rb
|
57
57
|
rdoc_options:
|
58
58
|
- --title
|
59
59
|
- bisac Documentation
|
data/specs/data/bisac_po.bsc
DELETED
@@ -1,112 +0,0 @@
|
|
1
|
-
00000019013725 Rainbow Book 061112INTERNET.BSC F03901375X
|
2
|
-
1000002 14976 9013725 901375X 061112000000Y 000000001N00020000000
|
3
|
-
4000003 14976 Y000000000102978513220000100000000000000000000550000000
|
4
|
-
4100004 14976 Finding Sanctuary :Monastic St
|
5
|
-
4200005 14976 JAMISON ABBOT CHRISTOPH
|
6
|
-
4000006 14976 Y000000000203407855780000100000000000000000000550000000
|
7
|
-
4100007 14976 In My Own Words: Padre Pio
|
8
|
-
4200008 14976 CHIFFOLO ANTHONY
|
9
|
-
4000009 14976 Y000000000303408635440000100000000000000000000550000000
|
10
|
-
4100010 14976 Knowing God New Edn.With Study
|
11
|
-
4200011 14976 PACKER J I
|
12
|
-
4000012 14976 Y000000000403409111580000100000000000000000000550000000
|
13
|
-
4100013 14976 Everyone I See Is Luckier Than
|
14
|
-
4200014 14976 BEVAN CLARE
|
15
|
-
4000015 14976 Y000000000503409111740000100000000000000000000550000000
|
16
|
-
4100016 14976 I Want To Shout And Stamp Abou
|
17
|
-
4200017 14976 MITTON TONY
|
18
|
-
4000018 14976 Y000000000605670406230000100000000000000000000550000000
|
19
|
-
4100019 14976 Gnostics :Identifying an Ancie
|
20
|
-
4200020 14976 LOGAN, ALASTAIR
|
21
|
-
4000021 14976 Y000000000705670875140000100000000000000000000550000000
|
22
|
-
4100022 14976 Mary For All Christians
|
23
|
-
4200023 14976 MACQUARRIE J
|
24
|
-
4000024 14976 Y000000000806425620750000100000000000000000000550000000
|
25
|
-
4100025 14976 Forgiveness and Other Acts of
|
26
|
-
4200026 14976 DOWRICK STEPHANIE
|
27
|
-
4000027 14976 Y000000000907333174560000100000000000000000000550000000
|
28
|
-
4100028 14976 Honey and The Fires: Ancient s
|
29
|
-
4200029 14976 PULVERS ROGER & ALICE
|
30
|
-
4000030 14976 Y000000001007333179600000100000000000000000000550000000
|
31
|
-
4100031 14976 Mummy Book
|
32
|
-
4200032 14976 PARR TODD
|
33
|
-
4000033 14976 Y000000001107333198230000100000000000000000000550000000
|
34
|
-
4100034 14976 So Many Selves
|
35
|
-
4200035 14976 CAREY GABRIELLE
|
36
|
-
4000036 14976 Y000000001207336159880000100000000000000000000550000000
|
37
|
-
4100037 14976 New Glucose Revolution Pocket
|
38
|
-
4200038 14976 MILLET ET AL
|
39
|
-
4000039 14976 Y000000001307475413530000100000000000000000000550000000
|
40
|
-
4100040 14976 Achieving Emotional Literacy
|
41
|
-
4200041 14976 STEINER CLAUDE
|
42
|
-
4000042 14976 Y000000001407499210990000100000000000000000000550000000
|
43
|
-
4100043 14976 How Meditation Heals
|
44
|
-
4200044 14976 HARRISON ERIC
|
45
|
-
4000045 14976 Y000000001507499242170000100000000000000000000550000000
|
46
|
-
4100046 14976 Other Side and Back :A Psychic
|
47
|
-
4200047 14976 BROWNE SYLVIA
|
48
|
-
4000048 14976 Y000000001607502213130000100000000000000000000550000000
|
49
|
-
4100049 14976 I'm Worried :Your Emotions Pb
|
50
|
-
4200050 14976 MOSES BRIAN
|
51
|
-
4000051 14976 Y000000001707502213210000100000000000000000000550000000
|
52
|
-
4100052 14976 It's Not Fair :Your Feelings P
|
53
|
-
4200053 14976 MOSES BRIAN
|
54
|
-
4000054 14976 Y000000001807538205440000100000000000000000000550000000
|
55
|
-
4100055 14976 Memory and Identity :Personal
|
56
|
-
4200056 14976 PAUL JOHN II
|
57
|
-
4000057 14976 Y000000001908192198190000100000000000000000000550000000
|
58
|
-
4100058 14976 Gift of Faith (Morehouse) :Sho
|
59
|
-
4200059 14976 NEFF LAVONNE
|
60
|
-
4000060 14976 Y0000000020082646520X0000200000000000000000000550000000
|
61
|
-
4100061 14976 Pastoral Prayers
|
62
|
-
4200062 14976 DEADMAN R
|
63
|
-
4000063 14976 Y000000002108264685000000200000000000000000000550000000
|
64
|
-
4100064 14976 Dignity of Difference P/B: How
|
65
|
-
4200065 14976 SACKS JONATHAN
|
66
|
-
4000066 14976 Y000000002208264733770000100000000000000000000550000000
|
67
|
-
4100067 14976 Celebrating Life :Finding happ
|
68
|
-
4200068 14976 SACKS JONATHAN
|
69
|
-
4000069 14976 Y000000002308264748100000100000000000000000000550000000
|
70
|
-
4100070 14976 From Optimism to Hope
|
71
|
-
4200071 14976 SACKS JONATHAN
|
72
|
-
4000072 14976 Y000000002408264785570000100000000000000000000550000000
|
73
|
-
4100073 14976 Persistence of Faith :Religion
|
74
|
-
4200074 14976 JONATHAN SACKS
|
75
|
-
4000075 14976 Y000000002508264794210000100000000000000000000550000000
|
76
|
-
4100076 14976 Shape of the Liturgy New Ed.
|
77
|
-
4200077 14976 DIX GREGORY
|
78
|
-
4000078 14976 Y000000002608601242580000200000000000000000000550000000
|
79
|
-
4100079 14976 Essence of Prayer
|
80
|
-
4200080 14976 BURROWS RUTH
|
81
|
-
4000081 14976 Y000000002715633841400000100000000000000000000550000000
|
82
|
-
4100082 14976 Theological Perspectives On Go
|
83
|
-
4200083 14976 MILBANK & WRD
|
84
|
-
4000084 14976 Y000000002817411479210000200000000000000000000550000000
|
85
|
-
4100085 14976 David Suzuki
|
86
|
-
4200086 14976 SUZUKI DAVID
|
87
|
-
4000087 14976 Y000000002917411484640000100000000000000000000550000000
|
88
|
-
4100088 14976 Holism and Complementary Medic
|
89
|
-
4200089 14976 DI STEFANO VINCENT
|
90
|
-
4000090 14976 Y000000003018418129270000100000000000000000000550000000
|
91
|
-
4100091 14976 Personal power animals :for gu
|
92
|
-
4200092 14976 GAUDING MADONNA
|
93
|
-
4000093 14976 Y000000003118644894130000100000000000000000000550000000
|
94
|
-
4100094 14976 Earth Time
|
95
|
-
4200095 14976 SUZUKI DAVID
|
96
|
-
4000096 14976 Y000000003218650838440000100000000000000000000550000000
|
97
|
-
4100097 14976 Facing The Fifties
|
98
|
-
4200098 14976 O'CONNOR PETER
|
99
|
-
4000099 14976 Y000000003318650891760000100000000000000000000550000000
|
100
|
-
4100100 14976 Long Way from Rome A: Why the
|
101
|
-
4200101 14976 MCGILLION CHRIS (ED)
|
102
|
-
4000102 14976 Y000000003418891089600000100000000000000000000550000000
|
103
|
-
4100103 14976 14 Presentations for Fall (God
|
104
|
-
4200104 14976 BERRYMAN JEROME W
|
105
|
-
4000105 14976 Y000000003518891089790000100000000000000000000550000000
|
106
|
-
4100106 14976 20 Presentations for Winter (G
|
107
|
-
4200107 14976 BERRYMAN JEROME W
|
108
|
-
4000108 14976 Y000000003618891089870000100000000000000000000550000000
|
109
|
-
4100109 14976 20 Presentations for Spring (G
|
110
|
-
4200110 14976 BERRYMAN JEROME W
|
111
|
-
5000111 14976 0011000000000360000000040
|
112
|
-
90001120000000000036000010000000040000010000100000000000003600001000000000000000
|