Sha256: 4f723fb63e3ffd232cd96e56f22befd5274ba25baf83b0b84136b8e6d096816a

Contents?: true

Size: 1.18 KB

Versions: 8

Compression:

Stored size: 1.18 KB

Contents

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


module Whois
  class Record
    class Parser
      module Scanners

        class Base

          def initialize(content)
            @input = StringScanner.new(content)
          end

          def parse
            @ast = {}
            while !@input.eos?
              parse_content
            end
            @ast
          end

          # This method is the core of the parser.
          #
          # It should include the parser logic
          # to analyze, trim or consume a line.
          #
          # @abstract Implement in your parser.
          def parse_content
            raise NotImplementedError
          end


          def trim_empty_line
            @input.skip(/^\n/)
          end

          def trim_newline
            @input.skip(/\n/)
          end

          def error!(message)
            if @input.eos?
              raise ParserError, "Unexpected end of input."
            else
              raise ParserError, "#{message}: #{@input.peek(@input.string.length)}"
            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/base.rb
whois-2.0.6 lib/whois/record/parser/scanners/base.rb
whois-2.0.5 lib/whois/record/parser/scanners/base.rb
whois-2.0.4 lib/whois/record/parser/scanners/base.rb
whois-2.0.3 lib/whois/record/parser/scanners/base.rb
whois-2.0.2 lib/whois/record/parser/scanners/base.rb
whois-2.0.1 lib/whois/record/parser/scanners/base.rb
whois-2.0.0 lib/whois/record/parser/scanners/base.rb