bisac 0.9 → 0.9.1
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.
- data/README +2 -1
- data/Rakefile +3 -2
- data/lib/bisac.rb +2 -1
- data/lib/bisac/po.rb +11 -10
- data/lib/bisac/po_line_item.rb +26 -22
- data/lib/bisac/poa_line_item.rb +5 -5
- data/specs/new_bisac_spec.rb +1 -1
- data/specs/new_po_line_item_spec.rb +22 -1
- data/specs/new_po_spec.rb +1 -1
- data/specs/poa_line_item_spec.rb +1 -1
- data/specs/poa_spec.rb +2 -2
- metadata +32 -22
data/README
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
The Book Industry Standards and Communications (BISAC) Group is a US body that
|
2
2
|
among other things, has defined a set of plain text data formats for electronic
|
3
|
-
data exchange within the book industry.
|
3
|
+
data exchange within the book industry. These formats are now deprecated, but
|
4
|
+
are still in use in some place (including segments of the Australian market).
|
4
5
|
|
5
6
|
This set of classes are just convenience wrappers around some of those formats,
|
6
7
|
designed to make reading and writing them just a little less painful.
|
data/Rakefile
CHANGED
@@ -6,7 +6,7 @@ require 'rake/testtask'
|
|
6
6
|
require "rake/gempackagetask"
|
7
7
|
require 'spec/rake/spectask'
|
8
8
|
|
9
|
-
PKG_VERSION = "0.9"
|
9
|
+
PKG_VERSION = "0.9.1"
|
10
10
|
PKG_NAME = "bisac"
|
11
11
|
PKG_FILE_NAME = "#{PKG_NAME}-#{PKG_VERSION}"
|
12
12
|
RUBYFORGE_PROJECT = 'rbook'
|
@@ -72,7 +72,8 @@ spec = Gem::Specification.new do |spec|
|
|
72
72
|
spec.extra_rdoc_files = %w{README COPYING LICENSE}
|
73
73
|
spec.rdoc_options << '--title' << 'bisac Documentation' <<
|
74
74
|
'--main' << 'README' << '-q'
|
75
|
-
spec.add_dependency('
|
75
|
+
spec.add_dependency('isbn10', '>= 1.0')
|
76
|
+
spec.add_dependency('ean13', '>= 1.0')
|
76
77
|
spec.author = "James Healy"
|
77
78
|
spec.email = "jimmy@deefa.com"
|
78
79
|
spec.rubyforge_project = "rbook"
|
data/lib/bisac.rb
CHANGED
data/lib/bisac/po.rb
CHANGED
@@ -37,7 +37,7 @@ module Bisac
|
|
37
37
|
attr_accessor :do_not_ship_before
|
38
38
|
attr_accessor :items
|
39
39
|
|
40
|
-
# creates a new
|
40
|
+
# creates a new Bisac::PO object
|
41
41
|
def initialize
|
42
42
|
@items = []
|
43
43
|
|
@@ -50,7 +50,7 @@ module Bisac
|
|
50
50
|
# reads a bisac text file into memory. input should be a string
|
51
51
|
# that specifies the file path
|
52
52
|
def self.load_from_file(input)
|
53
|
-
$stderr.puts "WARNING:
|
53
|
+
$stderr.puts "WARNING: Bisac::PO.load_from_file is deprecated. It only returns the first PO in the file. use parse_file instead."
|
54
54
|
self.parse_file(input) { |msg| return msg }
|
55
55
|
return nil
|
56
56
|
end
|
@@ -98,7 +98,7 @@ module Bisac
|
|
98
98
|
yield self.build_message(data) if data.size > 0
|
99
99
|
end
|
100
100
|
|
101
|
-
# creates a
|
101
|
+
# creates a Bisac::PO object from a string. Input should
|
102
102
|
# be a complete bisac file as a string
|
103
103
|
def self.load_from_string(input)
|
104
104
|
$stderr.puts "WARNING: Bisac::PO.load_from_string is deprecated. It only returns the first PO in the string. use parse_string instead."
|
@@ -152,8 +152,9 @@ module Bisac
|
|
152
152
|
@items.each_with_index do |item, idx|
|
153
153
|
item.line_item_number = idx + 1
|
154
154
|
item.sequence_number = sequence
|
155
|
-
|
156
|
-
|
155
|
+
new_lines = item.to_s.split("\n")
|
156
|
+
lines += new_lines
|
157
|
+
sequence += new_lines.size
|
157
158
|
end
|
158
159
|
|
159
160
|
# PO control
|
@@ -173,11 +174,11 @@ module Bisac
|
|
173
174
|
line[7,20] = @items.size.to_s.rjust(13,"0")
|
174
175
|
line[20,5] = "00001" # total '10' (PO) records
|
175
176
|
line[25,10] = total_qty.to_s.rjust(10,"0")
|
176
|
-
line[35,5] = "
|
177
|
-
line[40,5] = "
|
178
|
-
line[55,5] =
|
179
|
-
line[60,5] = "
|
180
|
-
line[65,5] = "
|
177
|
+
line[35,5] = lines.select { |l| l[0,1] == "0"}.size.to_s.rjust(5,"0") # number of '00'-'09' records
|
178
|
+
line[40,5] = lines.select { |l| l[0,1] == "0"}.size.to_s.rjust(5,"0") # number of '10'-'19' records
|
179
|
+
line[55,5] = lines.select { |l| l[0,1] == "4"}.size.to_s.rjust(5,"0") # number of '40'-'49' records
|
180
|
+
line[60,5] = lines.select { |l| l[0,1] == "5"}.size.to_s.rjust(5,"0") # number of '50'-'59' records
|
181
|
+
line[65,5] = lines.select { |l| l[0,1] == "6"}.size.to_s.rjust(5,"0") # number of '60'-'69' records
|
181
182
|
lines << line
|
182
183
|
|
183
184
|
lines.join("\n")
|
data/lib/bisac/po_line_item.rb
CHANGED
@@ -37,10 +37,10 @@ module Bisac
|
|
37
37
|
end
|
38
38
|
|
39
39
|
def isbn=(val)
|
40
|
-
if
|
40
|
+
if EAN13.valid?(val)
|
41
41
|
@isbn = val
|
42
|
-
elsif
|
43
|
-
@isbn =
|
42
|
+
elsif ISBN10.valid?(val)
|
43
|
+
@isbn = ISBN10.new(val).to_ean
|
44
44
|
else
|
45
45
|
@isbn = val
|
46
46
|
end
|
@@ -48,19 +48,19 @@ module Bisac
|
|
48
48
|
|
49
49
|
# is the isbn for this product valid?
|
50
50
|
def isbn?
|
51
|
-
|
51
|
+
EAN13.valid?(@isbn)
|
52
52
|
end
|
53
53
|
|
54
54
|
def isbn10
|
55
|
-
if isbn?
|
56
|
-
|
55
|
+
if isbn? && @isbn[0,3] == "978"
|
56
|
+
ISBN10.complete(@isbn[3,9])
|
57
57
|
else
|
58
58
|
@isbn
|
59
59
|
end
|
60
60
|
end
|
61
61
|
|
62
62
|
def to_s
|
63
|
-
lines = [""
|
63
|
+
lines = [""]
|
64
64
|
lines[0] << "40"
|
65
65
|
lines[0] << @sequence_number.to_s.rjust(5,"0")
|
66
66
|
lines[0] << " "
|
@@ -79,21 +79,25 @@ module Bisac
|
|
79
79
|
lines[0] << @isbn
|
80
80
|
end
|
81
81
|
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
82
|
+
if @title && @title.to_s.size > 0
|
83
|
+
lines << ""
|
84
|
+
lines[1] << "41"
|
85
|
+
lines[1] << (@sequence_number + 1).to_s.rjust(5,"0")
|
86
|
+
lines[1] << " "
|
87
|
+
lines[1] << @po_number.to_s.ljust(11," ")
|
88
|
+
lines[1] << " "
|
89
|
+
lines[1] << pad_trunc(@title, 30)
|
90
|
+
end
|
91
|
+
|
92
|
+
if @author && @author.to_s.size > 0
|
93
|
+
lines << ""
|
94
|
+
lines[2] << "42"
|
95
|
+
lines[2] << (@sequence_number + 2).to_s.rjust(5,"0")
|
96
|
+
lines[2] << " "
|
97
|
+
lines[2] << @po_number.to_s.ljust(11," ")
|
98
|
+
lines[2] << " " # TODO
|
99
|
+
lines[2] << pad_trunc(@author, 30)
|
100
|
+
end
|
97
101
|
|
98
102
|
lines.join("\n")
|
99
103
|
end
|
data/lib/bisac/poa_line_item.rb
CHANGED
@@ -45,8 +45,8 @@ module Bisac
|
|
45
45
|
def isbn=(val)
|
46
46
|
if val == ""
|
47
47
|
@isbn = nil
|
48
|
-
elsif
|
49
|
-
@isbn =
|
48
|
+
elsif ISBN10.valid?(val)
|
49
|
+
@isbn = ISBN10.new(val).to_ean
|
50
50
|
else
|
51
51
|
@isbn = val
|
52
52
|
end
|
@@ -54,12 +54,12 @@ module Bisac
|
|
54
54
|
|
55
55
|
# is the isbn for this product valid?
|
56
56
|
def isbn?
|
57
|
-
|
57
|
+
EAN13.valid?(@isbn || "")
|
58
58
|
end
|
59
59
|
|
60
60
|
def isbn10
|
61
|
-
if isbn?
|
62
|
-
|
61
|
+
if isbn? && @isbn[0,3] == "978"
|
62
|
+
ISBN10.complete(@isbn[3,9])
|
63
63
|
else
|
64
64
|
@isbn
|
65
65
|
end
|
data/specs/new_bisac_spec.rb
CHANGED
@@ -4,7 +4,7 @@ require 'bisac'
|
|
4
4
|
|
5
5
|
context "A new bisac purchase order line item object" do
|
6
6
|
|
7
|
-
|
7
|
+
before(:each) do
|
8
8
|
@valid_row = "4000003 14976 Y000000000102978513220000100000000000000000000550000000"
|
9
9
|
@valid_row_two = "4000033 13424 Y000000001107538214940000200000000000000000000400000000 \n"
|
10
10
|
@valid_isbn13_row = "4000003 14627 Y000000000103855198500000600000000000000000000400000000 9780385519854"
|
@@ -49,4 +49,25 @@ context "A new bisac purchase order line item object" do
|
|
49
49
|
lambda { Bisac::POLineItem.load_from_string(@invalid_row_nil) }.should raise_error(ArgumentError)
|
50
50
|
lambda { Bisac::POLineItem.load_from_string(@invalid_row_num) }.should raise_error(ArgumentError)
|
51
51
|
end
|
52
|
+
|
53
|
+
specify "Should render into a single line if no title or author are provided" do
|
54
|
+
item = Bisac::POLineItem.load_from_string(@valid_isbn13_row)
|
55
|
+
|
56
|
+
item.to_s.split("\n").size.should eql(1)
|
57
|
+
end
|
58
|
+
|
59
|
+
specify "Should render into two lines if a title is provided" do
|
60
|
+
item = Bisac::POLineItem.load_from_string(@valid_isbn13_row)
|
61
|
+
item.title = "test title"
|
62
|
+
|
63
|
+
item.to_s.split("\n").size.should eql(2)
|
64
|
+
end
|
65
|
+
|
66
|
+
specify "Should render into three lines if a title and author are provided" do
|
67
|
+
item = Bisac::POLineItem.load_from_string(@valid_isbn13_row)
|
68
|
+
item.title = "test title"
|
69
|
+
item.author = "test author"
|
70
|
+
|
71
|
+
item.to_s.split("\n").size.should eql(3)
|
72
|
+
end
|
52
73
|
end
|
data/specs/new_po_spec.rb
CHANGED
@@ -4,7 +4,7 @@ require 'bisac'
|
|
4
4
|
|
5
5
|
context "A new bisac purchase order object" do
|
6
6
|
|
7
|
-
|
7
|
+
before(:each) do
|
8
8
|
@valid_file = File.dirname(__FILE__) + "/data/bisac_po.txt"
|
9
9
|
@valid_multi_file = File.dirname(__FILE__) + "/data/bisac_multi_po.txt"
|
10
10
|
@invalid_file_no_header = File.dirname(__FILE__) + "/data/bisac_po_no_header.txt"
|
data/specs/poa_line_item_spec.rb
CHANGED
@@ -4,7 +4,7 @@ require 'bisac'
|
|
4
4
|
|
5
5
|
context "A new bisac purchase order line item object" do
|
6
6
|
|
7
|
-
|
7
|
+
before(:each) do
|
8
8
|
@valid_row = "40000030000000019629000000000107112260670000100000000000000000 000000000101 "
|
9
9
|
@valid_isbn13_row = "40000030000000019629000000000107112260670000100000000000000000 000000000101 9780711226067"
|
10
10
|
end
|
data/specs/poa_spec.rb
CHANGED
@@ -4,7 +4,7 @@ require 'bisac'
|
|
4
4
|
|
5
5
|
context "The BISAC POA Class" do
|
6
6
|
|
7
|
-
|
7
|
+
before(:each) do
|
8
8
|
@valid_file = File.dirname(__FILE__) + "/data/valid_poa.txt"
|
9
9
|
@invalid_file_onix = File.dirname(__FILE__) + "/data/single_product.xml"
|
10
10
|
end
|
@@ -26,7 +26,7 @@ end
|
|
26
26
|
|
27
27
|
context "A BISAC POA object" do
|
28
28
|
|
29
|
-
|
29
|
+
before(:each) do
|
30
30
|
@valid_file = File.dirname(__FILE__) + "/data/valid_poa.txt"
|
31
31
|
@invalid_file_onix = File.dirname(__FILE__) + "/data/single_product.xml"
|
32
32
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bisac
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 0.9.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Healy
|
@@ -9,11 +9,11 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date:
|
12
|
+
date: 2010-02-16 00:00:00 +11:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
|
-
name:
|
16
|
+
name: isbn10
|
17
17
|
type: :runtime
|
18
18
|
version_requirement:
|
19
19
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -22,7 +22,17 @@ dependencies:
|
|
22
22
|
- !ruby/object:Gem::Version
|
23
23
|
version: "1.0"
|
24
24
|
version:
|
25
|
-
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: ean13
|
27
|
+
type: :runtime
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: "1.0"
|
34
|
+
version:
|
35
|
+
description: " This library is designed to make working with various BISAC\n file formats easier.\n"
|
26
36
|
email: jimmy@deefa.com
|
27
37
|
executables: []
|
28
38
|
|
@@ -34,33 +44,33 @@ extra_rdoc_files:
|
|
34
44
|
- LICENSE
|
35
45
|
files:
|
36
46
|
- lib/bisac.rb
|
37
|
-
- lib/bisac
|
38
|
-
- lib/bisac/
|
47
|
+
- lib/bisac/utils.rb
|
48
|
+
- lib/bisac/poa_line_item.rb
|
39
49
|
- lib/bisac/po.rb
|
50
|
+
- lib/bisac/message.rb
|
51
|
+
- lib/bisac/poa.rb
|
40
52
|
- lib/bisac/po_line_item.rb
|
41
53
|
- lib/bisac/product.rb
|
42
|
-
-
|
43
|
-
-
|
44
|
-
-
|
45
|
-
- specs/
|
46
|
-
- specs/data/bisac_multi_po.txt
|
54
|
+
- specs/new_po_spec.rb
|
55
|
+
- specs/new_bisac_spec.rb
|
56
|
+
- specs/poa_spec.rb
|
57
|
+
- specs/poa_line_item_spec.rb
|
47
58
|
- specs/data/bisac_po.txt
|
48
|
-
- specs/data/
|
49
|
-
- specs/data/bisac_po_no_header.txt
|
59
|
+
- specs/data/valid_poa.txt
|
50
60
|
- specs/data/valid_bisac.txt
|
61
|
+
- specs/data/bisac_multi_po.txt
|
62
|
+
- specs/data/bisac_po_no_header.txt
|
51
63
|
- specs/data/single_product.xml
|
52
|
-
- specs/data/
|
53
|
-
- specs/new_bisac_spec.rb
|
64
|
+
- specs/data/bisac_po_no_footer.txt
|
54
65
|
- specs/new_po_line_item_spec.rb
|
55
|
-
- specs/new_po_spec.rb
|
56
|
-
- specs/poa_spec.rb
|
57
|
-
- specs/poa_line_item_spec.rb
|
58
66
|
- Rakefile
|
59
67
|
- README
|
60
68
|
- COPYING
|
61
69
|
- LICENSE
|
62
70
|
has_rdoc: true
|
63
71
|
homepage: http://rbook.rubyforge.org/
|
72
|
+
licenses: []
|
73
|
+
|
64
74
|
post_install_message:
|
65
75
|
rdoc_options:
|
66
76
|
- --title
|
@@ -85,13 +95,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
85
95
|
requirements: []
|
86
96
|
|
87
97
|
rubyforge_project: rbook
|
88
|
-
rubygems_version: 1.3.
|
98
|
+
rubygems_version: 1.3.5
|
89
99
|
signing_key:
|
90
|
-
specification_version:
|
100
|
+
specification_version: 3
|
91
101
|
summary: A library for manipulating BISAC files
|
92
102
|
test_files:
|
93
|
-
- specs/new_bisac_spec.rb
|
94
|
-
- specs/new_po_line_item_spec.rb
|
95
103
|
- specs/new_po_spec.rb
|
104
|
+
- specs/new_bisac_spec.rb
|
96
105
|
- specs/poa_spec.rb
|
97
106
|
- specs/poa_line_item_spec.rb
|
107
|
+
- specs/new_po_line_item_spec.rb
|