3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
# File 'lib/lisbn/ranges.rb', line 3
def self.to_yaml
xml = Nori.new.parse(
File.read(File.dirname(__FILE__) + '/../../data/RangeMessage.xml')
)
ranges = xml["ISBNRangeMessage"]["RegistrationGroups"]["Group"]
hash = Array(ranges).flatten.inject({}) do |memo, group|
prefix = group["Prefix"].gsub(/-/, '').to_s
ranges = Array(group["Rules"]["Rule"]).flatten.map do |rule|
length = rule["Length"].to_i
next unless length > 0
{:range => Range.new(*rule["Range"].split("-").map {|r| r[0..(length - 1)].to_i }), :length => length}
end.compact
memo.update(prefix => ranges)
end
YAML::dump(hash)
end
|