class Whois::SafeRecord

Attributes

record[R]
target[R]

Public Class Methods

define_method_method(method) click to toggle source

@api private

# File lib/whois/safe_record.rb, line 18
    def self.define_method_method(method)
      class_eval <<-RUBY, __FILE__, __LINE__ + 1
        def #{method}(*args, &block)
          if parser.respond_to?(:#{method})
            parser.#{method}(*args, &block)
          end
        end
      RUBY
    end
define_property_method(method) click to toggle source

@api private

# File lib/whois/safe_record.rb, line 7
    def self.define_property_method(method)
      class_eval <<-RUBY, __FILE__, __LINE__ + 1
        def #{method}(*args, &block)
          if property_any_supported?(:#{method})
            parser.#{method}(*args, &block)
          end
        end
      RUBY
    end
define_question_method(method) click to toggle source

@api private

# File lib/whois/safe_record.rb, line 29
    def self.define_question_method(method)
      return if method.to_s.end_with?("?")
      class_eval <<-RUBY, __FILE__, __LINE__ + 1
        def #{method}?
          !#{method}.nil?
        end
      RUBY
    end
new(record) click to toggle source
# File lib/whois/safe_record.rb, line 53
def initialize(record)
  @record = record
end

Public Instance Methods

admin_contact() click to toggle source

Shortcut for #admin_contacts.first.

@see Whois::Parser#admin_contacts

@return [Whois::Parser::Contact]

If the property is supported and a contact exists.

@return [nil]

If the property is not supported or the contact doesn't exist.
# File lib/whois/safe_record.rb, line 113
def admin_contact
  if property_any_supported?(:admin_contacts)
    admin_contacts.first
  end
end
contacts() click to toggle source

Collects and returns all the contacts.

@see Whois::Parser#contacts

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

# File lib/whois/safe_record.rb, line 138
def contacts
  parser.contacts
end
parser() click to toggle source

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

@return [Whois::Parser]

# File lib/whois/safe_record.rb, line 75
def parser
  @parser ||= Parser.new(record)
end
properties() click to toggle source

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

@return [{ Symbol => Object }]

# File lib/whois/safe_record.rb, line 83
def properties
  hash = {}
  Parser::PROPERTIES.each do |property|
    hash[property] = __send__(property)
  end
  hash
end
registrant_contact() click to toggle source

Shortcut for #registrant_contacts.first.

@see Whois::Parser#registrant_contacts

@return [Whois::Parser::Contact]

If the property is supported and a contact exists.

@return [nil]

If the property is not supported or the contact doesn't exist.
# File lib/whois/safe_record.rb, line 99
def registrant_contact
  if property_any_supported?(:registrant_contacts)
    registrant_contacts.first
  end
end
respond_to?(*args) click to toggle source

Checks if this class respond to given method.

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

@return [Boolean]

# File lib/whois/safe_record.rb, line 67
def respond_to?(*args)
  respond_to_parser_method?(args.first) || target.respond_to?(*args)
end
technical_contact() click to toggle source

Shortcut for #technical_contacts.first.

@see Whois::Parser#technical_contacts

@return [Whois::Parser::Contact]

If the property is supported and a contact exists.

@return [nil]

If the property is not supported or the contact doesn't exist.
# File lib/whois/safe_record.rb, line 127
def technical_contact
  if property_any_supported?(:technical_contacts)
    technical_contacts.first
  end
end

Private Instance Methods

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

Delegates any missing method to Record.

# File lib/whois/safe_record.rb, line 164
def method_missing(method, *args, &block)
  target.send(method, *args, &block)
end
property_any_supported?(property) click to toggle source

Checks if the property passed as symbol is supported in any of the parsers.

@api private @see Whois::Parser::Parser#property_any_supported?

@param [Symbol] property The name of the property to check. @return [Boolean]

# File lib/whois/safe_record.rb, line 159
def property_any_supported?(property)
  parser.property_any_supported?(property)
end
respond_to_parser_method?(symbol) click to toggle source

@api private

# File lib/whois/safe_record.rb, line 146
def respond_to_parser_method?(symbol)
  name = symbol.to_s =~ /\?$/ ? symbol.to_s[0..-2] : symbol
  Parser::PROPERTIES.include?(name.to_sym) || Parser::METHODS.include?(name.to_sym)
end