Sha256: 3eb3e346be963ec40d0e254067ccd124b8c90ee9173c76a0a47d68ac49c52ce5

Contents?: true

Size: 1.32 KB

Versions: 47

Compression:

Stored size: 1.32 KB

Contents

#
# = Ruby Whois
#
# An intelligent pure Ruby WHOIS client and parser.
#
#
# Category::    Net
# Package::     Whois
# Author::      Simone Carletti <weppos@weppos.net>
# License::     MIT License
#
#--
#
#++


require 'strscan'


module Whois
  class Answer
    class Parser

      # The Ast module tries to emulate a super-simple Abstract Syntax Tree structure
      # including method for accessing ast nodes.
      #
      # == Usage
      #
      # Include the Ast module and provide a <tt>parse</tt> instance method.
      # <tt>parse</tt> should returns a Hash representing the AST.
      #
      #   def parse
      #     Scanner.new.parse
      #   end
      #   # => { "created_on" => "2009-12-12", ... }
      #
      # Now you can access the AST using the <tt>node</tt> method.
      #
      #   node "created_on"
      #   # => "2009-12-12"
      #
      #   node? "created_on"
      #   # => true
      #
      #   node? "created_at"
      #   # => false
      #
      module Ast

        def ast
          @ast ||= parse
        end

        def node(key, &block)
          if block_given?
            value = ast[key]
            value = yield(value) unless value.nil?
            value
          else
            ast[key]
          end
        end

        def node?(key)
          !ast[key].nil?
        end

      end

    end
  end
end

Version data entries

47 entries across 47 versions & 1 rubygems

Version Path
whois-1.6.6 lib/whois/answer/parser/ast.rb
whois-1.6.5 lib/whois/answer/parser/ast.rb
whois-1.6.4 lib/whois/answer/parser/ast.rb
whois-1.6.3 lib/whois/answer/parser/ast.rb
whois-1.6.2 lib/whois/answer/parser/ast.rb
whois-1.6.1 lib/whois/answer/parser/ast.rb
whois-1.6.0 lib/whois/answer/parser/ast.rb
whois-1.5.1 lib/whois/answer/parser/ast.rb
whois-1.5.0 lib/whois/answer/parser/ast.rb
whois-1.3.11 lib/whois/answer/parser/ast.rb
whois-1.3.10 lib/whois/answer/parser/ast.rb
whois-1.3.9 lib/whois/answer/parser/ast.rb
whois-1.3.8 lib/whois/answer/parser/ast.rb
whois-1.3.7 lib/whois/answer/parser/ast.rb
whois-1.3.6 lib/whois/answer/parser/ast.rb
whois-1.3.5 lib/whois/answer/parser/ast.rb
whois-1.3.4 lib/whois/answer/parser/ast.rb
whois-1.3.3 lib/whois/answer/parser/ast.rb
whois-1.3.2 lib/whois/answer/parser/ast.rb
whois-1.3.1 lib/whois/answer/parser/ast.rb