Sha256: 977be1d7dcdf6dbf1176f243580cce8145293bf676eeec6c9c12d0da044292d3

Contents?: true

Size: 1.22 KB

Versions: 2

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

2 entries across 2 versions & 1 rubygems

Version Path
whois-2.2.0 lib/whois/record/parser/scanners/cnnic.rb
whois-2.1.0 lib/whois/record/parser/scanners/cnnic.rb