Sha256: 963b2946aa62dbc4d62424e273620c9eabefdfcdada14867437b88edd6f5f2e2

Contents?: true

Size: 1.22 KB

Versions: 8

Compression:

Stored size: 1.22 KB

Contents

#--
# Ruby Whois
#
# An intelligent pure Ruby WHOIS client and parser.
#
# Copyright (c) 2009-2011 Simone Carletti <weppos@weppos.net>
#++


require 'whois/record/parser/scanners/base'


module Whois
  class Record
    class Parser
      module Scanners

        class Cnnic < Scanners::Base

          def parse_content
            parse_reserved    ||
            parse_available   ||
            parse_keyvalue    ||
            trim_newline      ||
            error!("Unexpected token")
          end

          def parse_available
            if @input.scan(/^no matching record/)
              @ast["status-available"] = true
            end
          end

          def parse_reserved
            if @input.scan(/^the domain you want to register is reserved/)
              @ast["status-reserved"] = true
            end
          end

          def parse_keyvalue
            if @input.scan(/(.+?):(.*?)\n/)
              key, value = @input[1].strip, @input[2].strip
              if @ast[key].nil?
                @ast[key] = value
              else
                @ast[key].is_a?(Array) || @ast[key] = [@ast[key]]
                @ast[key] << value
              end
            end
          end

        end

      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
whois-2.0.7 lib/whois/record/parser/scanners/cnnic.rb
whois-2.0.6 lib/whois/record/parser/scanners/cnnic.rb
whois-2.0.5 lib/whois/record/parser/scanners/cnnic.rb
whois-2.0.4 lib/whois/record/parser/scanners/cnnic.rb
whois-2.0.3 lib/whois/record/parser/scanners/cnnic.rb
whois-2.0.2 lib/whois/record/parser/scanners/cnnic.rb
whois-2.0.1 lib/whois/record/parser/scanners/cnnic.rb
whois-2.0.0 lib/whois/record/parser/scanners/cnnic.rb