Permalink
Browse files

Scanner-based .IE parser

  • Loading branch information...
1 parent 6b10af5 commit f68473a6f6868cf877dff986def71edcee92fa7f @weppos committed Mar 21, 2012
@@ -8,6 +8,7 @@
require 'whois/record/parser/base'
+require 'whois/record/scanners/whois.domainregistry.ie.rb'
module Whois
@@ -26,22 +27,21 @@ class Parser
# and examples.
#
class WhoisDomainregistryIe < Base
+ include Scanners::Ast
property_supported :status do
- if content_for_scanner =~ /status:\s+(.+)\n/
- case $1.downcase
- when "active"
- :registered
- else
- Whois.bug!(ParserError, "Unknown status `#{$1}'.")
- end
- else
+ case node("status", &:downcase)
+ when nil
:available
+ when "active"
+ :registered
+ else
+ Whois.bug!(ParserError, "Unknown status `#{node("status")}'.")
end
end
property_supported :available? do
- !!(content_for_scanner =~ /^% Not Registered/)
+ !!node("status:available")
end
property_supported :registered? do
@@ -54,19 +54,27 @@ class WhoisDomainregistryIe < Base
property_not_supported :updated_on
property_supported :expires_on do
- if content_for_scanner =~ /renewal:\s+(.+)\n/
- Time.parse($1)
- end
+ node("renewal") { |value| Time.parse(value) }
end
property_supported :nameservers do
- content_for_scanner.scan(/nserver:\s+(.+)\n/).flatten.map do |line|
+ Array.wrap(node("nserver")).map do |line|
name, ipv4 = line.split(/\s+/)
Record::Nameserver.new(:name => name, :ipv4 => ipv4)
end
end
+
+ # Initializes a new {Scanners::WhoisDomainregistryIe} instance
+ # passing the {#content_for_scanner}
+ # and calls +parse+ on it.
+ #
+ # @return [Hash]
+ def parse
+ Scanners::WhoisDomainregistryIe.new(content_for_scanner).parse
+ end
+
end
end
@@ -27,7 +27,7 @@ class WhoisCctldBy < Base
]
tokenizer :scan_available do
- if @input.scan(/^Object does not exist/)
+ if @input.skip(/^Object does not exist/)
@ast["status:available"] = true
end
end
@@ -0,0 +1,46 @@
+#--
+# Ruby Whois
+#
+# An intelligent pure Ruby WHOIS client and parser.
+#
+# Copyright (c) 2009-2012 Simone Carletti <weppos@weppos.net>
+#++
+
+require 'whois/record/scanners/base'
+
+module Whois
+ class Record
+ module Scanners
+
+ # Scanner for the whois.domainregistry.ie server.
+ #
+ # @since RELEASE
+ class WhoisDomainregistryIe < Base
+
+ self.tokenizers += [
+ :skip_empty_line,
+ :scan_copyright,
+ :scan_keyvalue,
+ :scan_available,
+ ]
+
+ tokenizer :scan_available do
+ if @input.skip(/^% Not Registered - .+\n/)
+ @ast["status:available"] = true
+ end
+ end
+
+ tokenizer :scan_copyright do
+ if @input.match?(/^% Rights restricted by copyright/)
+ lines = []
+ while @input.scan(/^%(.+)\n/)
+ lines << @input[1].strip
+ end
+ @ast["field:disclaimer"] = lines.join(" ")
+ end
+ end
+
+ end
+ end
+ end
+end

0 comments on commit f68473a

Please sign in to comment.