class Whois::Record::Scanners::Base
Attributes
settings[R]
Public Class Methods
new(settings = nil)
click to toggle source
# File lib/whois/record/scanners/base.rb, line 26 def initialize(settings = nil) @settings = settings || {} end
tokenizer(name, &block)
click to toggle source
# File lib/whois/record/scanners/base.rb, line 19 def self.tokenizer(name, &block) define_method(name, &block) end
Public Instance Methods
parse(content)
click to toggle source
# File lib/whois/record/scanners/base.rb, line 30 def parse(content) # The temporary store. # Scanners may use this to store pointers, states or other flags. @tmp = {} # A super-simple AST store. @ast = {} @input = StringScanner.new(content) tokenize until @input.eos? @ast end
Protected Instance Methods
_scan_keyvalues(pattern)
click to toggle source
# File lib/whois/record/scanners/base.rb, line 92 def _scan_keyvalues(pattern) results = [] while @input.scan(/(.+?):(.*?)\n/) key, value = @input[1].strip, @input[2].strip if results[key].nil? results[key] = value else results[key] = Array.wrap(results[key]) results[key] << value end end end
_scan_lines_to_array(pattern)
click to toggle source
# File lib/whois/record/scanners/base.rb, line 75 def _scan_lines_to_array(pattern) results = [] while @input.scan(pattern) @input[1].strip results << @input[1].strip end results end
_scan_lines_to_hash(pattern)
click to toggle source
# File lib/whois/record/scanners/base.rb, line 84 def _scan_lines_to_hash(pattern) results = {} while @input.scan(pattern) results.merge! @input[1].strip => @input[2].strip end results end
Private Instance Methods
error!(message)
click to toggle source
# File lib/whois/record/scanners/base.rb, line 118 def error!(message) raise ParserError, "#{message}: #{@input.peek(@input.string.length)}" end
tokenize()
click to toggle source
# File lib/whois/record/scanners/base.rb, line 107 def tokenize tokenizers.each do |tokenizer| return if send(tokenizer) end unexpected_token end
unexpected_token()
click to toggle source
# File lib/whois/record/scanners/base.rb, line 114 def unexpected_token error!("Unexpected token") end