Permalink
Browse files

Change (registrant|admin|technical)_contact properties to return an A…

…rray of Contact.
  • Loading branch information...
1 parent 4375b6d commit 0af79a95d4d903a3d006df6f95e5e4b57532b049 @weppos committed Mar 8, 2011
View
49 lib/whois/answer.rb
@@ -43,7 +43,7 @@ def initialize(server, parts)
# Checks if this class respond to given method.
#
# Overrides the default implementation to add support
- # for {PROPERTIES} and {METHODS}.
+ # for {Parser::PROPERTIES} and {Parser::METHODS}.
#
# @returns [Boolean]
def respond_to?(symbol, include_private = false)
@@ -166,6 +166,51 @@ def properties
# @group Methods
+ # Shortcut for <tt>#registrant_contacts.first</tt>.
+ #
+ # @return [Whois::Answer::Contact]
+ # If the property is supported and a contact exists.
+ # @return [nil]
+ # If the property is not supported or the contact doesn't exist.
+ #
+ # @see Answer#registrant_contacts
+ #
+ def registrant_contact
+ if property_supported?(:registrant_contacts)
+ parser.registrant_contacts.first
+ end
+ end
+
+ # Shortcut for <tt>#admin_contacts.first</tt>.
+ #
+ # @return [Whois::Answer::Contact]
+ # If the property is supported and a contact exists.
+ # @return [nil]
+ # If the property is not supported or the contact doesn't exist.
+ #
+ # @see Answer#admin_contacts
+ #
+ def admin_contact
+ if property_supported?(:admin_contacts)
+ parser.admin_contacts.first
+ end
+ end
+
+ # Shortcut for <tt>#technical_contacts.first</tt>.
+ #
+ # @return [Whois::Answer::Contact]
+ # If the property is supported and a contact exists.
+ # @return [nil]
+ # If the property is not supported or the contact doesn't exist.
+ #
+ # @see Answer#technical_contacts
+ #
+ def technical_contact
+ if property_supported?(:technical_contacts)
+ parser.technical_contacts.first
+ end
+ end
+
# Collects and returns all the contacts.
#
# @return [Array<Whois::Answer::Contact>]
@@ -251,8 +296,6 @@ def self.define_property_method(method)
def #{method}(*args, &block)
if property_supported?(:#{method})
parser.#{method}(*args, &block)
- else
- nil
end
end
RUBY
View
2 lib/whois/answer/parser.rb
@@ -41,7 +41,7 @@ class Parser
:status, :available?, :registered?,
:created_on, :updated_on, :expires_on,
:registrar,
- :registrant_contact, :admin_contact, :technical_contact,
+ :registrant_contacts, :admin_contacts, :technical_contacts,
:nameservers,
]
View
4 lib/whois/answer/parser/base.rb
@@ -309,8 +309,8 @@ def validate!
# @see Whois::Answer::Parser#contacts
#
def contacts
- [:registrant_contact, :admin_contact, :technical_contact].inject([]) do |contacts, property|
- contacts += Array.wrap(send(property)) if property_supported?(property)
+ [:registrant_contacts, :admin_contacts, :technical_contacts].inject([]) do |contacts, property|
+ contacts += send(property) if property_supported?(property)
contacts
end
end
View
6 spec/whois/answer/parser/base_spec.rb
@@ -182,9 +182,9 @@
c2 = Whois::Answer::Contact.new(:id => "2nd", :name => "foo")
c3 = Whois::Answer::Contact.new(:id => "3rd", :name => "foo")
i = Class.new(klass) do
- property_register(:registrant_contact, :supported) { [c1, c2] }
- property_register(:admin_contact, :supported) { nil }
- property_register(:technical_contact, :supported) { c3 }
+ property_register(:registrant_contacts, :supported) { [c1, c2] }
+ property_register(:admin_contacts, :supported) { [] }
+ property_register(:technical_contacts, :supported) { [c3] }
end.new(@part)
i.contacts.should == [c1, c2, c3]
View
8 spec/whois/answer/parser_spec.rb
@@ -201,13 +201,13 @@ class Whois::Answer::Parser::Contacts1Test < Whois::Answer::Parser::Base
end
class Whois::Answer::Parser::Contacts2Test < Whois::Answer::Parser::Base
- property_supported(:technical_contact) { "p2-t1" }
- property_supported(:admin_contact) { "p2-a1" }
- property_supported(:registrant_contact) { nil }
+ property_supported(:technical_contacts) { ["p2-t1"] }
+ property_supported(:admin_contacts) { ["p2-a1"] }
+ property_supported(:registrant_contacts) { [] }
end
class Whois::Answer::Parser::Contacts3Test< Whois::Answer::Parser::Base
- property_supported(:technical_contact) { "p3-t1" }
+ property_supported(:technical_contacts) { ["p3-t1"] }
end
it "returns an empty array when 0 parts" do
View
4 spec/whois/answer_spec.rb
@@ -361,13 +361,13 @@ def happy; "yes"; end
end.should raise_error(NoMethodError)
end
- it "doesn't catch all methods" do
+ it "does not catch all methods" do
lambda do
klass.new(nil, []).i_am_not_defined
end.should raise_error(NoMethodError)
end
- it "doesn't catch all question methods" do
+ it "does not catch all question methods" do
lambda do
klass.new(nil, []).i_am_not_defined?
end.should raise_error(NoMethodError)

0 comments on commit 0af79a9

Please sign in to comment.