Sha256: 2ed56beea691564b17997eb603838d994dca2d45ca4757620e02c9540df3f99a
Contents?: true
Size: 1.53 KB
Versions: 3
Compression:
Stored size: 1.53 KB
Contents
#-- # Ruby Whois # # An intelligent pure Ruby WHOIS client and parser. # # Copyright (c) 2009-2013 Simone Carletti <weppos@weppos.net> #++ require 'strscan' module Whois class Record module Scanners # The Scannable module tries to emulate a super-simple Abstract Syntax Tree structure # including method for accessing ast nodes. # # == Usage # # Include the Scannable module and set the `self.scanner` value. # # class ParserFoo # include Scannable # # self.scanner = ScannerFoo # end # # 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 Scannable def self.included(base) base.class_attribute :scanner end def node(key) 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 def parse scanner = self.scanner.is_a?(Array) ? self.scanner.first : self.scanner settings = self.scanner.is_a?(Array) ? self.scanner.last : {} scanner.new(settings).parse(content_for_scanner) end private def ast @ast ||= parse end end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
whois-3.4.3 | lib/whois/record/scanners/scannable.rb |
whois-3.4.2 | lib/whois/record/scanners/scannable.rb |
whois-3.4.1 | lib/whois/record/scanners/scannable.rb |