Skip to content

Commit

Permalink
Scanner-based .IE parser
Browse files Browse the repository at this point in the history
  • Loading branch information
weppos committed Mar 21, 2012
1 parent 6b10af5 commit f68473a
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 14 deletions.
34 changes: 21 additions & 13 deletions lib/whois/record/parser/whois.domainregistry.ie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@


require 'whois/record/parser/base'
require 'whois/record/scanners/whois.domainregistry.ie.rb'


module Whois
Expand All @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/whois/record/scanners/whois.cctld.by.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
46 changes: 46 additions & 0 deletions lib/whois/record/scanners/whois.domainregistry.ie.rb
Original file line number Diff line number Diff line change
@@ -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.