lisbn 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/README.md +9 -0
- data/Rakefile +2 -0
- data/data/ranges.yml +4974 -0
- data/lib/lisbn.rb +4 -2
- data/lib/lisbn/lisbn.rb +1 -16
- data/lib/lisbn/ranges.rb +31 -0
- data/lisbn.gemspec +1 -1
- metadata +4 -2
data/lib/lisbn.rb
CHANGED
data/lib/lisbn/lisbn.rb
CHANGED
@@ -116,20 +116,5 @@ private
|
|
116
116
|
isbn[-1..-1] == isbn_13_checksum
|
117
117
|
end
|
118
118
|
|
119
|
-
|
120
|
-
rngs = Nori.new.parse(File.read(File.dirname(__FILE__) + '/../../data/RangeMessage.xml'))
|
121
|
-
Array(rngs["ISBNRangeMessage"]["RegistrationGroups"]["Group"]).flatten.inject({}) do |memo, group|
|
122
|
-
prefix = group["Prefix"].gsub(/-/, '')
|
123
|
-
ranges = Array(group["Rules"]["Rule"]).flatten.map do |rule|
|
124
|
-
length = rule["Length"].to_i
|
125
|
-
next unless length > 0
|
126
|
-
|
127
|
-
{:range => Range.new(*rule["Range"].split("-").map {|r| r[0..(length - 1)].to_i }), :length => length}
|
128
|
-
end.compact
|
129
|
-
|
130
|
-
memo.update(prefix => ranges)
|
131
|
-
end
|
132
|
-
end
|
133
|
-
|
134
|
-
RANGES = ranges
|
119
|
+
RANGES = YAML::load_file(File.dirname(__FILE__) + "/../../data/ranges.yml")
|
135
120
|
end
|
data/lib/lisbn/ranges.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
class Lisbn < String
|
2
|
+
module Ranges
|
3
|
+
def self.to_yaml
|
4
|
+
xml = Nori.new.parse(
|
5
|
+
File.read(File.dirname(__FILE__) + '/../../data/RangeMessage.xml')
|
6
|
+
)
|
7
|
+
|
8
|
+
ranges = xml["ISBNRangeMessage"]["RegistrationGroups"]["Group"]
|
9
|
+
|
10
|
+
hash = Array(ranges).flatten.inject({}) do |memo, group|
|
11
|
+
prefix = group["Prefix"].gsub(/-/, '')
|
12
|
+
ranges = Array(group["Rules"]["Rule"]).flatten.map do |rule|
|
13
|
+
length = rule["Length"].to_i
|
14
|
+
next unless length > 0
|
15
|
+
|
16
|
+
{:range => Range.new(*rule["Range"].split("-").map {|r| r[0..(length - 1)].to_i }), :length => length}
|
17
|
+
end.compact
|
18
|
+
|
19
|
+
memo.update(prefix => ranges)
|
20
|
+
end
|
21
|
+
|
22
|
+
YAML::dump(hash)
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.save_to_yaml!
|
26
|
+
File.open(File.dirname(__FILE__) + "/../../data/ranges.yml", "w") do |f|
|
27
|
+
f.write(to_yaml)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/lisbn.gemspec
CHANGED
@@ -12,7 +12,7 @@ Gem::Specification.new do |gem|
|
|
12
12
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
13
13
|
gem.name = "lisbn"
|
14
14
|
gem.require_paths = ["lib"]
|
15
|
-
gem.version = "0.2.
|
15
|
+
gem.version = "0.2.1"
|
16
16
|
|
17
17
|
gem.add_dependency "nori", "~> 2.0"
|
18
18
|
gem.add_dependency "nokogiri"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lisbn
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mike Ragalie
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-05-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nori
|
@@ -67,9 +67,11 @@ files:
|
|
67
67
|
- README.md
|
68
68
|
- Rakefile
|
69
69
|
- data/RangeMessage.xml
|
70
|
+
- data/ranges.yml
|
70
71
|
- lib/lisbn.rb
|
71
72
|
- lib/lisbn/cache_method.rb
|
72
73
|
- lib/lisbn/lisbn.rb
|
74
|
+
- lib/lisbn/ranges.rb
|
73
75
|
- lisbn.gemspec
|
74
76
|
- spec/cache_method_spec.rb
|
75
77
|
- spec/lisbn_spec.rb
|