Module: Whois::Scanners::Scannable
- Included in:
- Parsers::BaseAfilias, Parsers::BaseAfilias2, Parsers::BaseCocca2, Parsers::BaseIcannCompliant, Parsers::BaseIisse, Parsers::BaseShared1, Parsers::BaseShared2, Parsers::BaseShared3, Parsers::BaseVerisign, Parsers::BaseWhoisd, Parsers::WhoisAtiTn, Parsers::WhoisAudnsNetAu, Parsers::WhoisCctldBy, Parsers::WhoisCentralnicCom, Parsers::WhoisCiraCa, Parsers::WhoisCnnicCn, Parsers::WhoisDenicDe, Parsers::WhoisDnsHr, Parsers::WhoisDomainregistryIe, Parsers::WhoisFi, Parsers::WhoisIanaOrg, Parsers::WhoisNc, Parsers::WhoisNicIt, Parsers::WhoisRegistryNetZa, Parsers::WhoisRnidsRs, Parsers::WhoisSmallregistryNet, Parsers::WhoisSrsNetNz, Parsers::WhoisSx, Parsers::WhoisTldEe, Parsers::WhoisYoursrsCom
- Defined in:
- lib/whois/scanners/scannable.rb
Overview
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 node method.
node "created_on"
# => "2009-12-12"
node? "created_on"
# => true
node? "created_at"
# => false
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.included(base) ⇒ Object
32 33 34 |
# File 'lib/whois/scanners/scannable.rb', line 32 def self.included(base) base.class_attribute :scanner end |
Instance Method Details
#node(key) ⇒ Object
36 37 38 39 40 41 42 43 44 |
# File 'lib/whois/scanners/scannable.rb', line 36 def node(key) if block_given? value = ast[key] value = yield(value) unless value.nil? value else ast[key] end end |
#node?(key) ⇒ Boolean
46 47 48 |
# File 'lib/whois/scanners/scannable.rb', line 46 def node?(key) !ast[key].nil? end |
#parse ⇒ Object
50 51 52 53 54 |
# File 'lib/whois/scanners/scannable.rb', line 50 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 |