Sha256: 91e7b7ac08d1ae2d87ceb35d75820f7de6782628ad01c37d526474fa445ae268
Contents?: true
Size: 794 Bytes
Versions: 2
Compression:
Stored size: 794 Bytes
Contents
class PublicSuffixList module Parser # com # *.jp # *.hokkaido.jp # *.tokyo.jp # !pref.hokkaido.jp # !metro.tokyo.jp # { # "com" => {:term => true}, # "jp" => { # "tokyo" => {"!metro" => {:term => true}, "*" => {:term => true}}, # "hokkaido" => {"!pref" => {:term => true}, "*" => {:term => true}}, # "*" => {:term => true} # } # } def self.parse(lines) lines.inject({}) do |acc, line| line.gsub!(/\s.*/, "") unless line =~ %r{//} or line.empty? tmp = acc line.split(".").reject(&:empty?).reverse.each do |p| tmp[p] = {} unless tmp[p] tmp = tmp[p] end tmp[:term] = true end acc end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
public-suffix-list-0.2.1 | lib/public_suffix_list/parser.rb |
public-suffix-list-0.2.0 | lib/public_suffix_list/parser.rb |