module Whois::ParserExtensions::WhoisRecord

Public Class Methods

included(base) click to toggle source
# File lib/whois/parser_extensions/whois_record.rb, line 8
def self.included(base)
  base.extend ClassMethods
end

Public Instance Methods

admin_contact() click to toggle source

Shortcut for #admin_contacts.first.

@see Whois::Record#admin_contacts

@return [Whois::Record::Contact]

If the property is supported and a contact exists.

@return [nil]

If the contact doesn't exist.

@raise [Whois::AttributeNotSupported, Whois::AttributeNotImplemented]

# File lib/whois/parser_extensions/whois_record.rb, line 64
def admin_contact
  parser.admin_contacts.first
end
changed?(other) click to toggle source

Checks whether this {Whois::Record} is different than other.

Comparing the {Whois::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.

@see Whois::Parser#changed?

@param [Whois::Record] other The other record instance to compare. @return [Boolean]

# File lib/whois/parser_extensions/whois_record.rb, line 109
def changed?(other)
  !unchanged?(other)
end
contacts() click to toggle source

Collects and returns all the contacts.

@see Whois::Parser#contacts

@return [Array<Whois::Record::Contact>]

# File lib/whois/parser_extensions/whois_record.rb, line 86
def contacts
  warn("#{self.class}#contacts is deprecated")
  parser.contacts
end
parser() click to toggle source

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

@return [Whois::Record::Parser]

# File lib/whois/parser_extensions/whois_record.rb, line 26
def parser
  @parser ||= Parser.new(self)
end
properties() click to toggle source

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

@return [{ Symbol => Object }] @raise [Whois::AttributeNotSupported, Whois::AttributeNotImplemented]

# 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) click to toggle source

@deprecated

# 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_contact() click to toggle source

Shortcut for #registrant_contacts.first.

@see Whois::Record#registrant_contacts

@return [Whois::Record::Contact]

If the property is supported and a contact exists.

@return [nil]

If the the contact doesn't exist.

@raise [Whois::AttributeNotSupported, Whois::AttributeNotImplemented]

# 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) click to toggle source

Checks if this class respond to given method.

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

@return [Boolean]

Calls superclass method
# 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?() click to toggle source

Checks whether this is an incomplete response.

@deprecated @see Whois::Parser#response_incomplete?

@return [Boolean]

# 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?() click to toggle source

Checks whether this is a throttle response.

@deprecated @see Whois::Parser#response_throttled?

@return [Boolean]

# 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?() click to toggle source

Checks whether this is an unavailable response.

@deprecated @see Whois::Parser#response_unavailable?

@return [Boolean]

# 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_contact() click to toggle source

Shortcut for #technical_contacts.first.

@see Whois::Record#technical_contacts

@return [Whois::Record::Contact]

If the property is supported and a contact exists.

@return [nil]

If the contact doesn't exist.

@raise [Whois::AttributeNotSupported, Whois::AttributeNotImplemented]

# File lib/whois/parser_extensions/whois_record.rb, line 77
def technical_contact
  parser.technical_contacts.first
end
unchanged?(other) click to toggle source

The opposite of {#changed?}.

@see Whois::Parser#unchanged?

@param [Whois::Record] other The other record instance to compare. @return [Boolean]

# 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

Private Instance Methods

method_missing(method, *args, &block) click to toggle source

Delegates all method calls to the internal parser.

Calls superclass method
# File lib/whois/parser_extensions/whois_record.rb, line 184
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?($1.to_sym)
    self.class.define_question_method($1)
    send(method)
  else
    super
  end
end
respond_to_parser_method?(symbol) click to toggle source

@api private

# File lib/whois/parser_extensions/whois_record.rb, line 170
def respond_to_parser_method?(symbol)
  Parser::PROPERTIES.include?(symbol) ||
    Parser::METHODS.include?(symbol) ||
    respond_to_question_method?(symbol)
end
respond_to_question_method?(symbol) click to toggle source
# File lib/whois/parser_extensions/whois_record.rb, line 176
def respond_to_question_method?(symbol)
  return false unless symbol.to_s =~ /([a-z_]+)\?/
  symbol = $1.to_sym
  Parser::PROPERTIES.include?(symbol) ||
      Parser::METHODS.include?(symbol)
end