Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Extract shared parsers.

  • Loading branch information...
commit c37586c5af328973ea14208a2a13e96b4f8ca322 1 parent 0e7c68b
@weppos authored
View
120 lib/whois/record/parser/base_shared1.rb
@@ -0,0 +1,120 @@
+#--
+# Ruby Whois
+#
+# An intelligent pure Ruby WHOIS client and parser.
+#
+# Copyright (c) 2009-2012 Simone Carletti <weppos@weppos.net>
+#++
+
+
+require 'whois/record/parser/base'
+require 'whois/record/scanners/base_shared1'
+
+
+module Whois
+ class Record
+ class Parser
+
+ # Shared parser 1.
+ #
+ # @abstract
+ #
+ # @since RELEASE
+ class BaseShared1 < Base
+ include Scanners::Ast
+
+ property_not_supported :disclaimer
+
+
+ property_supported :domain do
+ node('Domain Name')
+ end
+
+ property_not_supported :domain_id
+
+
+ property_not_supported :referral_whois
+
+ property_not_supported :referral_url
+
+
+ property_supported :status do
+ Array.wrap(node("Status"))
+ end
+
+ property_supported :available? do
+ !!node('status:available')
+ end
+
+ property_supported :registered? do
+ !available?
+ end
+
+
+ property_not_supported :created_on
+
+ property_not_supported :updated_on
+
+ property_not_supported :expires_on
+
+
+ property_supported :registrar do
+ node('Registrar Name') do |name|
+ Record::Registrar.new(
+ :id => node('Registrar ID'),
+ :name => node('Registrar Name'),
+ :organization => node('Registrar Name')
+ )
+ end
+ end
+
+
+ property_supported :registrant_contacts do
+ build_contact('Registrant', Whois::Record::Contact::TYPE_REGISTRANT)
+ end
+
+ property_not_supported :admin_contacts
+
+ property_supported :technical_contacts do
+ build_contact('Tech', Whois::Record::Contact::TYPE_TECHNICAL)
+ end
+
+
+ property_supported :nameservers do
+ node('Name Server') do |value|
+ ipv4s = node('Name Server IP') || Array.new(value.size)
+ value.zip(ipv4s).map do |name, ipv4|
+ Nameserver.new(:name => name, :ipv4 => ipv4)
+ end
+ end
+ end
+
+
+ # Initializes a new {Scanners::WhoisRegistryOm} instance
+ # passing the {#content_for_scanner}
+ # and calls +parse+ on it.
+ #
+ # @return [Hash]
+ def parse
+ Scanners::BaseShared1.new(content_for_scanner).parse
+ end
+
+
+ private
+
+ def build_contact(element, type)
+ node("#{element} Contact ID") do
+ Record::Contact.new(
+ :type => type,
+ :id => node("#{element} Contact ID"),
+ :name => node("#{element} Contact Name"),
+ :email => node("#{element} Contact Email")
+ )
+ end
+ end
+
+ end
+
+ end
+ end
+end
View
101 lib/whois/record/parser/whois.registry.om.rb
@@ -7,8 +7,7 @@
#++
-require 'whois/record/parser/base'
-require 'whois/record/scanners/whois.registry.om.rb'
+require 'whois/record/parser/base_shared1'
module Whois
@@ -21,103 +20,7 @@ class Parser
# The Example parser for the list of all available methods.
#
# @since 2.6.0
- class WhoisRegistryOm < Base
- include Scanners::Ast
-
- property_not_supported :disclaimer
-
-
- property_supported :domain do
- node('Domain Name')
- end
-
- property_not_supported :domain_id
-
-
- property_not_supported :referral_whois
-
- property_not_supported :referral_url
-
-
- property_supported :status do
- case (s = node('Status'))
- when nil
- :available
- when 'ok'
- :registered
- else
- Whois.bug!(ParserError, "Unknown status `#{s}'.")
- end
- end
-
- property_supported :available? do
- !!node('status:available')
- end
-
- property_supported :registered? do
- !available?
- end
-
-
- property_not_supported :created_on
-
- property_not_supported :updated_on
-
- property_not_supported :expires_on
-
-
- property_supported :registrar do
- node('Registrar Name') do |name|
- Record::Registrar.new(
- :name => name
- )
- end
- end
-
-
- property_supported :registrant_contacts do
- build_contact('Registrant', Whois::Record::Contact::TYPE_REGISTRANT)
- end
-
- property_not_supported :admin_contacts
-
- property_supported :technical_contacts do
- build_contact('Tech', Whois::Record::Contact::TYPE_TECHNICAL)
- end
-
-
- property_supported :nameservers do
- node('Name Server') do |names|
- names.map do |name|
- Record::Nameserver.new(:name => name)
- end
- end
- end
-
-
- # Initializes a new {Scanners::WhoisRegistryOm} instance
- # passing the {#content_for_scanner}
- # and calls +parse+ on it.
- #
- # @return [Hash]
- def parse
- Scanners::WhoisRegistryOm.new(content_for_scanner).parse
- end
-
-
- private
-
- def build_contact(element, type)
- node("#{element} Contact ID") do
- Record::Contact.new(
- :type => type,
- :id => node("#{element} Contact ID"),
- :name => node("#{element} Contact Name"),
- :email => node("#{element} Contact Email")
- )
- end
- end
-
+ class WhoisRegistryOm < BaseShared1
end
end
View
96 lib/whois/record/parser/whois.registry.qa.rb
@@ -7,8 +7,7 @@
#++
-require 'whois/record/parser/base'
-require 'whois/record/scanners/whois.registry.qa.rb'
+require 'whois/record/parser/base_shared1'
module Whois
@@ -18,98 +17,7 @@ class Parser
# Parser for the whois.registry.qa server.
#
# @since 2.1.0
- class WhoisRegistryQa < Base
- include Scanners::Ast
-
- property_not_supported :disclaimer
-
-
- property_supported :domain do
- node("Domain Name")
- end
-
- property_not_supported :domain_id
-
-
- property_not_supported :referral_whois
-
- property_not_supported :referral_url
-
-
- property_supported :status do
- Array.wrap(node("Status"))
- end
-
- property_supported :available? do
- !!node("status:available")
- end
-
- property_supported :registered? do
- !available?
- end
-
-
- property_not_supported :created_on
-
- property_not_supported :updated_on
-
- property_not_supported :expires_on
-
-
- property_supported :registrar do
- node("Registrar ID") do |raw|
- Record::Registrar.new(
- :id => node("Registrar ID"),
- :name => node("Registrar Name"),
- :organization => node("Registrar Name")
- )
- end
- end
-
- property_supported :registrant_contacts do
- build_contact("Registrant Contact", Whois::Record::Contact::TYPE_REGISTRANT)
- end
-
- property_not_supported :admin_contacts
-
- property_supported :technical_contacts do
- build_contact("Tech Contact", Whois::Record::Contact::TYPE_TECHNICAL)
- end
-
-
- property_supported :nameservers do
- node("Name Server") do |value|
- ipv4s = node("Name Server IP") || Array.new(value.size)
- value.zip(ipv4s).map do |name, ipv4|
- Nameserver.new(:name => name, :ipv4 => ipv4)
- end
- end
- end
-
-
- # Initializes a new {Scanners::WhoisRegistryQa} instance
- # passing the {#content_for_scanner}
- # and calls +parse+ on it.
- #
- # @return [Hash]
- def parse
- Scanners::WhoisRegistryQa.new(content_for_scanner).parse
- end
-
-
- private
-
- def build_contact(element, type)
- node("#{element} ID") do |raw|
- Record::Contact.new(
- :type => type,
- :id => node("#{element} ID"),
- :name => node("#{element} Name"),
- :email => node("#{element} Email")
- )
- end
- end
-
+ class WhoisRegistryQa < BaseShared1
end
end
View
5 lib/whois/record/scanners/whois.registry.om.rb → lib/whois/record/scanners/base_shared1.rb
@@ -14,10 +14,7 @@ module Whois
class Record
module Scanners
- # Scanner for the whois.registry.om record.
- #
- # @since 2.6.0
- class WhoisRegistryOm < Base
+ class BaseShared1 < Base
self.tokenizers += [
:skip_empty_line,
View
39 lib/whois/record/scanners/whois.registry.qa.rb
@@ -1,39 +0,0 @@
-#--
-# 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.registry.qa record.
- #
- # @since 2.1.0
- class WhoisRegistryQa < Base
-
- self.tokenizers += [
- :skip_empty_line,
- :scan_available,
- :scan_keyvalue,
- ]
-
-
- tokenizer :scan_available do
- if @input.skip(/^No Data Found\n/)
- @ast['status:available'] = true
- end
- end
-
- end
-
- end
- end
-end
View
2  spec/fixtures/responses/whois.registry.om/status_available.expected
@@ -17,7 +17,7 @@
#status
- should: %s == :available
+ should: %s == []
#available?
should: %s == true
View
10 spec/fixtures/responses/whois.registry.om/status_registered.expected
@@ -17,7 +17,7 @@
#status
- should: %s == :registered
+ should: %s == ["ok"]
#available?
should: %s == false
@@ -40,7 +40,7 @@
should: %s CLASS(registrar)
should: %s.id == nil
should: %s.name == "Oman Telecommunication Company"
- should: %s.organization == nil
+ should: %s.organization == "Oman Telecommunication Company"
should: %s.url == nil
#registrant_contacts
@@ -88,13 +88,13 @@
should: %s SIZE(3)
should: %s[0] CLASS(nameserver)
should: %s[0].name == "om14.omantel.net.om"
- should: %s[0].ipv4 == nil
+ should: %s[0].ipv4 == "212.72.23.4"
should: %s[0].ipv6 == nil
should: %s[1] CLASS(nameserver)
should: %s[1].name == "om16.omantel.net.om"
- should: %s[1].ipv4 == nil
+ should: %s[1].ipv4 == "212.72.1.186"
should: %s[1].ipv6 == nil
should: %s[2] CLASS(nameserver)
should: %s[2].name == "om41.omantel.net.om"
- should: %s[2].ipv4 == nil
+ should: %s[2].ipv4 == "62.231.243.249"
should: %s[2].ipv6 == nil
View
2  spec/whois/record/parser/responses/whois.registry.om/status_available_spec.rb
@@ -48,7 +48,7 @@
end
describe "#status" do
it do
- subject.status.should == :available
+ subject.status.should == []
end
end
describe "#available?" do
View
10 spec/whois/record/parser/responses/whois.registry.om/status_registered_spec.rb
@@ -48,7 +48,7 @@
end
describe "#status" do
it do
- subject.status.should == :registered
+ subject.status.should == ["ok"]
end
end
describe "#available?" do
@@ -81,7 +81,7 @@
subject.registrar.should be_a(Whois::Record::Registrar)
subject.registrar.id.should == nil
subject.registrar.name.should == "Oman Telecommunication Company"
- subject.registrar.organization.should == nil
+ subject.registrar.organization.should == "Oman Telecommunication Company"
subject.registrar.url.should == nil
end
end
@@ -136,15 +136,15 @@
subject.nameservers.should have(3).items
subject.nameservers[0].should be_a(Whois::Record::Nameserver)
subject.nameservers[0].name.should == "om14.omantel.net.om"
- subject.nameservers[0].ipv4.should == nil
+ subject.nameservers[0].ipv4.should == "212.72.23.4"
subject.nameservers[0].ipv6.should == nil
subject.nameservers[1].should be_a(Whois::Record::Nameserver)
subject.nameservers[1].name.should == "om16.omantel.net.om"
- subject.nameservers[1].ipv4.should == nil
+ subject.nameservers[1].ipv4.should == "212.72.1.186"
subject.nameservers[1].ipv6.should == nil
subject.nameservers[2].should be_a(Whois::Record::Nameserver)
subject.nameservers[2].name.should == "om41.omantel.net.om"
- subject.nameservers[2].ipv4.should == nil
+ subject.nameservers[2].ipv4.should == "62.231.243.249"
subject.nameservers[2].ipv6.should == nil
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.