Sha256: ce409eaec21c975fc02558c2a1815e6d5fe0a5465b7ceb099548145b79a82b63

Contents?: true

Size: 1.13 KB

Versions: 2

Compression:

Stored size: 1.13 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

        # Scanner for the whois.registry.qa server response.
        #
        # @since  2.1.0
        class WhoisRegistryQa < Scanners::Base

          def parse_content
            parse_available ||
            parse_keyvalue_spaced ||

            trim_empty_line ||
            error!("Unexpected token")
          end

          def parse_available
            if @input.scan(/^No Data Found\n/)
              @ast["status:available"] = true
            end
          end

          def parse_keyvalue_spaced
            if @input.scan(/(.+?):\s+(.*?)\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/whois.registry.qa.rb
whois-2.1.0 lib/whois/record/parser/scanners/whois.registry.qa.rb