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.
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
# 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
# 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