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 176 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 AttributeNotImplemented 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 101 def self.property_not_implemented(property) property_register(property, Whois::Record::Parser::PROPERTY_STATE_NOT_IMPLEMENTED) class_eval( def _property_#{property}(*args) raise AttributeNotImplemented end private :_property_#{property}, __FILE__, __LINE__ + 1) end
Registers a property as "not supported" and defines the corresponding private _property_PROPERTY method.
A "not supported" property always raises a AttributeNotSupported 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 126 def self.property_not_supported(property) property_register(property, Whois::Record::Parser::PROPERTY_STATE_NOT_SUPPORTED) class_eval( def _property_#{property}(*args) raise AttributeNotSupported 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 83 def self.property_register(property, status) self._properties = self._properties.merge({ property => status }) end
Returns the status for the property passed as symbol.
@param [Symbol] property @return [Symbol, nil]
@example Undefined property
property_state(:disclaimer) # => nil
@example Defined property
property_register(:disclaimer, Whois::Record::Parser::PROPERTY_STATE_SUPPORTED) {} property_state(:disclaimer) # => :supported
# File lib/whois/record/parser/base.rb, line 48 def self.property_state(property) self._properties[property] 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_state?(:disclaimer) # => false
@example Registered property
property_register(:disclaimer) {} property_state?(:disclaimer) # => true
# File lib/whois/record/parser/base.rb, line 68 def self.property_state?(property, status = :any) if status == :any self._properties.key?(property) else self._properties[property] == status end 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 150 def self.property_supported(property, &block) property_register(property, Whois::Record::Parser::PROPERTY_STATE_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 280 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 249 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 197 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 214 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 163 def property_supported?(property) self.class.property_state?(property, Whois::Record::Parser::PROPERTY_STATE_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 292 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.