Module: Whois::ParserExtensions::WhoisRecord

Defined in:
lib/whois/parser_extensions/whois_record.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object (private)

Delegates all method calls to the internal parser.



185
186
187
188
189
190
191
192
193
194
195
196
197
198
# File 'lib/whois/parser_extensions/whois_record.rb', line 185

def method_missing(method, *args, &block)
  if Parser::PROPERTIES.include?(method)
    self.class.define_property_method(method)
    send(method, *args, &block)
  elsif Parser::METHODS.include?(method)
    self.class.define_method_method(method)
    send(method, *args, &block)
  elsif method.to_s =~ /([a-z_]+)\?/ and (Parser::PROPERTIES + Parser::METHODS).include?(::Regexp.last_match(1).to_sym)
    self.class.define_question_method(::Regexp.last_match(1))
    send(method)
  else
    super
  end
end

Class Method Details

.included(base) ⇒ Object



8
9
10
# File 'lib/whois/parser_extensions/whois_record.rb', line 8

def self.included(base)
  base.extend ClassMethods
end

Instance Method Details

#admin_contactWhois::Record::Contact?

Shortcut for #admin_contacts.first.

Returns:

  • (Whois::Record::Contact)

    If the property is supported and a contact exists.

  • (nil)

    If the contact doesn’t exist.

Raises:

See Also:

  • Record#admin_contacts


64
65
66
# File 'lib/whois/parser_extensions/whois_record.rb', line 64

def admin_contact
  parser.admin_contacts.first
end

#changed?(other) ⇒ Boolean

Checks whether this Record is different than other.

Comparing the Record content is not as trivial as you may think. WHOIS servers can inject into the WHOIS response strings that changes at every request, such as the timestamp the request was generated or the number of requests left for your current IP.

These strings causes a simple equal comparison to fail even if the registry data is the same.

This method should provide a bulletproof way to detect whether this record changed compared with other.

Parameters:

  • other (Whois::Record)

    The other record instance to compare.

Returns:

  • (Boolean)

See Also:



109
110
111
# File 'lib/whois/parser_extensions/whois_record.rb', line 109

def changed?(other)
  !unchanged?(other)
end

#contactsArray<Whois::Record::Contact>

Collects and returns all the contacts.

Returns:

  • (Array<Whois::Record::Contact>)

See Also:



86
87
88
89
# File 'lib/whois/parser_extensions/whois_record.rb', line 86

def contacts
  warn("#{self.class}#contacts is deprecated")
  parser.contacts
end

#parserWhois::Record::Parser

Lazy-loads and returns the parser proxy for current record.

Returns:

  • (Whois::Record::Parser)


26
27
28
# File 'lib/whois/parser_extensions/whois_record.rb', line 26

def parser
  @parser ||= Parser.new(self)
end

#properties{ Symbol => Object }

Returns a Hash containing all supported properties for this record along with corresponding values.

Returns:

  • ({ Symbol => Object })

Raises:



35
36
37
38
39
40
# File 'lib/whois/parser_extensions/whois_record.rb', line 35

def properties
  warn("#{self.class}#properties is deprecated")
  hash = {}
  Parser::PROPERTIES.each { |property| hash[property] = send(property) }
  hash
end

#property_any_supported?(property) ⇒ Boolean

Deprecated.

Returns:

  • (Boolean)


162
163
164
# File 'lib/whois/parser_extensions/whois_record.rb', line 162

def property_any_supported?(property)
  warn("#{self.class}#property_any_supported? is deprecated and has no effect. Use Whois::Parser.property_any_supported? if you need it.")
end

#registrant_contactWhois::Record::Contact?

Shortcut for #registrant_contacts.first.

Returns:

  • (Whois::Record::Contact)

    If the property is supported and a contact exists.

  • (nil)

    If the the contact doesn’t exist.

Raises:

See Also:

  • Record#registrant_contacts


51
52
53
# File 'lib/whois/parser_extensions/whois_record.rb', line 51

def registrant_contact
  parser.registrant_contacts.first
end

#respond_to_missing?(symbol, include_private = false) ⇒ Boolean

Checks if this class respond to given method.

Overrides the default implementation to add support for Whois::Parser::PROPERTIES and Whois::Parser::METHODS.

Returns:

  • (Boolean)


18
19
20
# File 'lib/whois/parser_extensions/whois_record.rb', line 18

def respond_to_missing?(symbol, include_private = false)
  respond_to_parser_method?(symbol) || super
end

#response_incomplete?Boolean

Deprecated.

Checks whether this is an incomplete response.

Returns:

  • (Boolean)

See Also:



133
134
135
136
# File 'lib/whois/parser_extensions/whois_record.rb', line 133

def response_incomplete?
  warn("#{self.class}#response_incomplete? is deprecated. Use parser.response_incomplete?")
  parser.response_incomplete?
end

#response_throttled?Boolean

Deprecated.

Checks whether this is a throttle response.

Returns:

  • (Boolean)

See Also:



144
145
146
147
# File 'lib/whois/parser_extensions/whois_record.rb', line 144

def response_throttled?
  warn("#{self.class}#response_throttled? is deprecated. Use parser.response_throttled?")
  parser.response_throttled?
end

#response_unavailable?Boolean

Deprecated.

Checks whether this is an unavailable response.

Returns:

  • (Boolean)

See Also:



155
156
157
158
# File 'lib/whois/parser_extensions/whois_record.rb', line 155

def response_unavailable?
  warn("#{self.class}#response_unavailable? is deprecated. Use parser.response_unavailable?")
  parser.response_unavailable?
end

#technical_contactWhois::Record::Contact?

Shortcut for #technical_contacts.first.

Returns:

  • (Whois::Record::Contact)

    If the property is supported and a contact exists.

  • (nil)

    If the contact doesn’t exist.

Raises:

See Also:

  • Record#technical_contacts


77
78
79
# File 'lib/whois/parser_extensions/whois_record.rb', line 77

def technical_contact
  parser.technical_contacts.first
end

#unchanged?(other) ⇒ Boolean

The opposite of #changed?.

Parameters:

  • other (Whois::Record)

    The other record instance to compare.

Returns:

  • (Boolean)

See Also:



119
120
121
122
123
124
125
# File 'lib/whois/parser_extensions/whois_record.rb', line 119

def unchanged?(other)
  unless other.is_a?(self.class)
    raise(ArgumentError, "Can't compare `#{self.class}' with `#{other.class}'")
  end

  equal?(other) || parser.unchanged?(other.parser)
end