Sha256: ce658f0d5eac1bf94116268bf0902158caffcb6cb800dc7497551dbd4341a895

Contents?: true

Size: 767 Bytes

Versions: 10

Compression:

Stored size: 767 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.strip!
        unless line =~ %r{//} or line.empty?
          tmp = acc
          line.split(".").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

10 entries across 10 versions & 1 rubygems

Version Path
public-suffix-list-0.1.6 lib/public_suffix_list/parser.rb
public-suffix-list-0.1.5 lib/public_suffix_list/parser.rb
public-suffix-list-0.1.4 lib/public_suffix_list/parser.rb
public-suffix-list-0.1.3 lib/public_suffix_list/parser.rb
public-suffix-list-0.1.2 lib/public_suffix_list/parser.rb
public-suffix-list-0.1.0 lib/public_suffix_list/parser.rb
public-suffix-list-0.0.6 lib/public_suffix_list/parser.rb
public-suffix-list-0.0.5 lib/public_suffix_list/parser.rb
public-suffix-list-0.0.4 lib/public_suffix_list/parser.rb
public-suffix-list-0.0.3 lib/public_suffix_list/parser.rb