Object
Represents the abstract base parser class for all server-specific parser implementations.
NOTE. This class is for the most part auto-generated via meta programming. This is the reason why RDoc can't detect and document all available methods.
@abstract
Initializes a new parser with given part.
@param [Whois::Record::Part] part
# File lib/whois/record/parser/base.rb, line 177 def initialize(part) @part = part @cached_properties = {} end
Registers a property as :not_implemented and defines the corresponding private _property_PROPERTY method.
A :not_implemented property always raises a PropertyNotImplemented error when the property method is called.
@param [Symbol] property @return [void]
@example Defining a not implemented property
# Defines a not implemented property called :disclaimer. property_not_implemented(:disclaimer)
# File lib/whois/record/parser/base.rb, line 102 def self.property_not_implemented(property) property_register(property, :not_implemented) class_eval( def _property_#{property}(*args) raise PropertyNotImplemented end private :_property_#{property}, __FILE__, __LINE__ + 1) end
Registers a property as :not_supported and defines the corresponding private _property_PROPERTY method.
A :not_implemented property always raises a PropertyNotSupported error when the property method is called.
@param [Symbol] property @return [void]
@example Defining an unsupported property
# Defines an unsupported property called :disclaimer. property_not_supported(:disclaimer)
# File lib/whois/record/parser/base.rb, line 127 def self.property_not_supported(property) property_register(property, :not_supported) class_eval( def _property_#{property}(*args) raise PropertyNotSupported end private :_property_#{property}, __FILE__, __LINE__ + 1) end
Registers a property in the registry.
@param [Symbol] property @param [Symbol] status
@return [void]
# File lib/whois/record/parser/base.rb, line 84 def self.property_register(property, status) self._properties = self._properties.merge({ property => status }) end
Check if the property passed as symbol is registered in the registry for current parser.
@param [Symbol] property @param [Symbol] status @return [Boolean]
@example Not-registered property
property_registered?(:disclaimer) # => false
@example Registered property
property_register(:disclaimer) {} property_registered?(:disclaimer) # => true
# File lib/whois/record/parser/base.rb, line 69 def self.property_registered?(property, status = :any) if status == :any self._properties.key?(property) else self._properties[property] == status end end
Returns the status for the property passed as symbol.
@param [Symbol] property @return [Symbol, nil]
@example Undefined property
property_status(:disclaimer) # => nil
@example Defined property
property_register(:disclaimer, :supported) {} property_status(:disclaimer) # => :supported
# File lib/whois/record/parser/base.rb, line 49 def self.property_status(property) self._properties[property] end
Registers a property as :supported and defines the corresponding private _property_PROPERTY method.
@param [Symbol] property @return [void]
@example Defining a supported property
# Defines a supported property called :disclaimer. property_supported(:disclaimer) do ... end
# File lib/whois/record/parser/base.rb, line 151 def self.property_supported(property, &block) property_register(property, :supported) define_method("_property_#{property}", &block) private :"_property_#{property}" end
Checks whether the content of this part is different than other.
Comparing a WHOIS response 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.
@param [Base] other The other parser instance to compare. @return [Boolean]
@see Whois::Record#changed? @see Whois::Record::Parser#changed?
# File lib/whois/record/parser/base.rb, line 281 def changed?(other) !unchanged?(other) end
Collects and returns all the available contacts.
@return [Array<Whois::Record::Contact>]
@see Whois::Record#contacts @see Whois::Record::Parser#contacts
# File lib/whois/record/parser/base.rb, line 250 def contacts [:registrant_contacts, :admin_contacts, :technical_contacts].inject([]) do |contacts, property| contacts += send(property) if property_supported?(property) contacts end end
This is an internal method primary used as a common access point to get the content to be parsed as a string.
The main reason behind this method is because, in the past, the internal representation of the data to be parsed changed several times, and I always had to rewrite all single parsers in order to reflect these changes. Now, as far as the parser access the data via the content method, there's no need to change each single implementation in case the content source changes.
That said, the only constraints about this method is to return the data to be parsed as string.
@return [String] The part body.
# File lib/whois/record/parser/base.rb, line 198 def content part.body end
Check if the parser respond to symbol and calls the method if defined. The method referenced by the symbol is supposed to be a question? method and to return a boolean.
@param [Symbol] symbol @return [Boolean]
@example
is(:response_throttled?) # => true
@api private
# File lib/whois/record/parser/base.rb, line 215 def is(symbol) respond_to?(symbol) && send(symbol) end
Checks if the property passed as symbol is supported by the current parser.
@param [Symbol] property The name of the property to check. @return [Boolean]
# File lib/whois/record/parser/base.rb, line 164 def property_supported?(property) self.class.property_registered?(property, :supported) end
Checks whether this is an incomplete response.
@return [Boolean]
@abstract This method is just a stub.
Define it in your parser class.
@see Whois::Record#response_incomplete? @see Whois::Record::Parser#response_incomplete?
# File lib/whois/record/parser/base.rb, line 312 def response_incomplete? end
Checks whether this is a throttle response.
@return [Boolean]
@abstract This method is just a stub.
Define it in your parser class.
@see Whois::Record#response_throttled? @see Whois::Record::Parser#response_throttled?
# File lib/whois/record/parser/base.rb, line 325 def response_throttled? end
The opposite of {changed?}.
@param [Base] other The other parser instance to compare. @return [Boolean]
@see Whois::Record#unchanged? @see Whois::Record::Parser#unchanged?
# File lib/whois/record/parser/base.rb, line 293 def unchanged?(other) unless other.is_a?(self.class) raise(ArgumentError, "Can't compare `#{self.class}' with `#{other.class}'") end equal?(other) || content_for_scanner == other.content_for_scanner end
Generated with the Darkfish Rdoc Generator 2.