Module Whois::Answer::Parser::Ast
In: lib/whois/answer/parser/ast.rb
lib/whois/answer/parser/ast.rb

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 parse instance method. parse 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 node method.

  node "created_on"
  # => "2009-12-12"

  node? "created_on"
  # => true

  node? "created_at"
  # => false

Methods

ast   ast   node   node   node?   node?  

Public Instance methods

[Source]

# File lib/whois/answer/parser/ast.rb, line 50
        def ast
          @ast ||= parse
        end

[Source]

# File lib/whois/answer/parser/ast.rb, line 50
        def ast
          @ast ||= parse
        end

[Source]

# File lib/whois/answer/parser/ast.rb, line 54
        def node(key, &block)
          if block_given?
            value = ast[key]
            value = yield(value) unless value.nil?
            value
          else
            ast[key]
          end
        end

[Source]

# File lib/whois/answer/parser/ast.rb, line 54
        def node(key, &block)
          if block_given?
            value = ast[key]
            value = yield(value) unless value.nil?
            value
          else
            ast[key]
          end
        end

[Source]

# File lib/whois/answer/parser/ast.rb, line 64
        def node?(key)
          !ast[key].nil?
        end

[Source]

# File lib/whois/answer/parser/ast.rb, line 64
        def node?(key)
          !ast[key].nil?
        end

[Validate]