Permalink
Browse files

WhoisTldEe scanner becomes Whoisd and learns how to scan the full con…

…tent.
  • Loading branch information...
1 parent aeb966b commit 514da94bc73dc930602c69f1969f154e5ea83640 @weppos committed Jul 3, 2012
@@ -20,6 +20,7 @@ class Parser
#
# @since RELEASE
class BaseWhoisd < Base
+ include Scanners::Ast
class_attribute :status_mapping
self.status_mapping = {
@@ -86,6 +87,16 @@ class BaseWhoisd < Base
end
end
+
+ # Initializes a new {Scanners::Whoisd} instance
+ # passing the {#content_for_scanner}
+ # and calls +parse+ on it.
+ #
+ # @return [Hash]
+ def parse
+ Scanners::Whoisd.new(content_for_scanner).parse
+ end
+
end
end
@@ -8,7 +8,7 @@
require 'whois/record/parser/base_whoisd'
-require 'whois/record/scanners/whois.tld.ee.rb'
+require 'whois/record/scanners/whoisd.rb'
module Whois
@@ -25,43 +25,31 @@ class Parser
# The Example parser for the list of all available methods.
#
class WhoisTldEe < BaseWhoisd
- include Scanners::Ast
property_supported :admin_contacts do
- if content_for_scanner =~ /admin-c:\s+(.+)\n/
- build_contact($1, Whois::Record::Contact::TYPE_ADMIN)
+ node('admin-c') do |value|
+ build_contact(value, Record::Contact::TYPE_ADMIN)
end
end
property_supported :registrant_contacts do
- if content_for_scanner =~ /registrant:\s+(.+)\n/
- build_contact($1, Whois::Record::Contact::TYPE_REGISTRANT)
+ node('registrant') do |value|
+ build_contact(value, Record::Contact::TYPE_REGISTRANT)
end
end
property_not_supported :technical_contacts
-
- # Initializes a new {Scanners::WhoisTldEe} instance
- # passing the {#content_for_scanner}
- # and calls +parse+ on it.
- #
- # @return [Hash]
- def parse
- Scanners::WhoisTldEe.new(content_for_scanner).parse
- end
-
-
private
def build_contact(element, type)
- node(element) do |raw|
+ node(element) do |hash|
Record::Contact.new(
:type => type,
:id => element,
- :name => raw["name"],
- :organization => raw["org"],
- :created_on => Time.parse(raw["created"])
+ :name => hash['name'],
+ :organization => hash['org'],
+ :created_on => Time.parse(hash['created'])
)
end
end
@@ -14,20 +14,19 @@ module Whois
class Record
module Scanners
- # Scanner for the whois.tld.ee record.
- #
- # @todo This is an incomplete scanner, it skips all the properties
- # except contacts.
- class WhoisTldEe < Base
+ # Scanner for Whoisd-based record.
+ class Whoisd < Base
self.tokenizers += [
- :scan_contact,
- :todo_content,
+ :skip_comment,
+ :skip_empty_line,
+ :scan_section,
+ :scan_keyvalue,
]
- tokenizer :scan_contact do
- if @input.scan(/contact:\s+(.*)\n/)
+ tokenizer :scan_section do
+ if @input.scan(/(?:contact|nsset):\s+(.+)\n/)
@tmp['_section'] = @input[1].strip
while scan_keyvalue
end
@@ -39,6 +38,10 @@ class WhoisTldEe < Base
@input.scan(/(.*)\n/)
end
+ tokenizer :skip_comment do
+ @input.skip(/^%.*\n/)
+ end
+
end
end

0 comments on commit 514da94

Please sign in to comment.