Sha256: b3197937716082b79be702ca1aacf687a55c0257af9b82f65daec5c5e8f0ca89
Contents?: true
Size: 1.48 KB
Versions: 18
Compression:
Stored size: 1.48 KB
Contents
# # bitclust/refsdatabase.rb # # This program is free software. # You can distribute this program under the Ruby License. # module BitClust # Corresponds to db-x.y.z/refs file. class RefsDatabase def self.load(src) if src.respond_to?(:to_str) buf = fopen(src.to_str, 'r:UTF-8'){|f| f.read} elsif src.respond_to?(:to_io) buf = src.to_io.read else buf = src.read end refs = self.new buf.each_line{|l| if /((?:\\,|[^,])+),((?:\\,|[^,])+),((?:\\,|[^,])+),((?:\\,|[^,])+)\n/ =~ l type, id, linkid, desc = [$1, $2, $3, $4].map{|e| e.gsub(/\\(.)/){|s| $1 == ',' ? ',' : s } } refs[type, id, linkid] = desc end } refs end def initialize @h = {} end def []=(type, mid, linkid, desc) @h[[type.to_s, mid, linkid]] = desc end def [](type, mid, linkid) @h[[type.to_s, mid, linkid]] end def save(s) if s.respond_to?(:to_str) path = s.to_str io = fopen(path, 'w:UTF-8') elsif s.respond_to?(:to_io) io = s.to_io else io = s end @h.each{|k, v| io.write( [k, v].flatten.map{|e| e.gsub(/,/, '\\,') }.join(',') + "\n" ) } io.close end def extract(entry) entry.source.each_line{|l| if /\A={1,6}\[a:(\w+)\] *(.*)/ =~ l entry.labels.each{|name| self[entry.class.type_id, name, $1] = $2 } end } end end end
Version data entries
18 entries across 18 versions & 1 rubygems