class Whois::SafeRecord
Attributes
Public Class Methods
@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
@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
@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
# File lib/whois/safe_record.rb, line 53 def initialize(record) @record = record end
Public Instance Methods
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
Collects and returns all the contacts.
@return [Array<Whois::Parser::Contact>]
# File lib/whois/safe_record.rb, line 138 def contacts parser.contacts end
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
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
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
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
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
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
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
@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