Class: Whois::Parser
- Inherits:
-
Object
- Object
- Whois::Parser
- Defined in:
- lib/whois/parser.rb,
lib/whois/parser/contact.rb,
lib/whois/parser/version.rb,
lib/whois/parser/registrar.rb,
lib/whois/parser/nameserver.rb
Defined Under Namespace
Classes: Contact, Nameserver, Registrar
Constant Summary collapse
- METHODS =
[ :contacts, :changed?, :unchanged?, # :response_incomplete?, :response_throttled?, :response_unavailable?, # :referral_whois, :referral_url, ]
- PROPERTIES =
[ :disclaimer, :domain, :domain_id, :status, :available?, :registered?, :created_on, :updated_on, :expires_on, :registrar, :registrant_contacts, :admin_contacts, :technical_contacts, :nameservers, ]
- PROPERTY_STATE_NOT_IMPLEMENTED =
:not_implemented
- PROPERTY_STATE_NOT_SUPPORTED =
:not_supported
- PROPERTY_STATE_SUPPORTED =
:supported
- VERSION =
The current library version.
"1.0.0".freeze
Instance Attribute Summary collapse
-
#record ⇒ Whois::Record
readonly
The record referenced by this parser.
Methods collapse
-
#contacts ⇒ Array<Whois::Record::Contact>
Collects and returns all the contacts from all the record parts.
Response collapse
-
#changed?(other) ⇒ Boolean
Loop through all the record parts to check if at least one part changed.
-
#response_incomplete? ⇒ Boolean
Loop through all the parts to check if at least one part is an incomplete response.
-
#response_throttled? ⇒ Boolean
Loop through all the parts to check if at least one part is a throttle response.
-
#response_unavailable? ⇒ Boolean
Loop through all the parts to check if at least one part is an unavailable response.
-
#unchanged?(other) ⇒ Boolean
The opposite of #changed?.
Class Method Summary collapse
-
.autoload(name) ⇒ void
Requires the file at
whois/parsers/#{name}
. -
.host_to_parser(host) ⇒ String
Converts
host
to the corresponding parser class name. -
.parser_for(part) ⇒ Whois::Parsers::Base
Returns the proper parser instance for given
part
. -
.parser_klass(host) ⇒ Class
Detects the proper parser class according to given
host
and returns the class constant.
Instance Method Summary collapse
-
#initialize(record) ⇒ Parser
constructor
Initializes and return a new parser from
record
. -
#parsers ⇒ Array<Whois::Parsers::Base>
Returns an array with all host-specific parsers initialized for the parts contained into this parser.
-
#property_any_not_implemented?(property) ⇒ Boolean
Checks if the
property
passed as symbol is “not implemented” in any of the parsers. -
#property_any_supported?(property) ⇒ Boolean
Checks if the
property
passed as symbol is supported in any of the parsers. -
#respond_to?(symbol, include_private = false) ⇒ Boolean
Checks if this class respond to given method.
Constructor Details
#initialize(record) ⇒ Parser
Initializes and return a new parser from record
.
172 173 174 |
# File 'lib/whois/parser.rb', line 172 def initialize(record) @record = record end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object (private)
330 331 332 333 334 335 336 337 338 339 340 |
# File 'lib/whois/parser.rb', line 330 def method_missing(method, *args, &block) if PROPERTIES.include?(method) self.class.define_property_method(method) send(method, *args, &block) elsif METHODS.include?(method) self.class.define_method_method(method) send(method, *args, &block) else super end end |
Instance Attribute Details
#record ⇒ Whois::Record (readonly)
Returns The record referenced by this parser.
165 166 167 |
# File 'lib/whois/parser.rb', line 165 def record @record end |
Class Method Details
.autoload(name) ⇒ void
This method returns an undefined value.
Requires the file at whois/parsers/#{name}
.
159 160 161 |
# File 'lib/whois/parser.rb', line 159 def self.autoload(name) require "whois/parsers/#{name}" end |
.host_to_parser(host) ⇒ String
Converts host
to the corresponding parser class name.
146 147 148 149 150 151 |
# File 'lib/whois/parser.rb', line 146 def self.host_to_parser(host) host.to_s.downcase. gsub(/[.-]/, '_'). gsub(/(?:^|_)(.)/) { $1.upcase }. gsub(/\A(\d+)\z/) { "Host#{$1}" } end |
.parser_for(part) ⇒ Whois::Parsers::Base
Returns the proper parser instance for given part
. The parser class is selected according to the value of the #host
attribute for given part
.
99 100 101 102 103 104 |
# File 'lib/whois/parser.rb', line 99 def self.parser_for(part) parser_klass(part.host).new(part) rescue LoadError Parsers.const_defined?("Blank") || autoload("blank") Parsers::Blank.new(part) end |
.parser_klass(host) ⇒ Class
Detects the proper parser class according to given host
and returns the class constant.
This method autoloads missing parser classes. If you want to define a custom parser, simple make sure the class is loaded in the Ruby environment before this method is called.
127 128 129 130 131 |
# File 'lib/whois/parser.rb', line 127 def self.parser_klass(host) name = host_to_parser(host) Parsers.const_defined?(name) || autoload(host) Parsers.const_get(name) end |
Instance Method Details
#changed?(other) ⇒ Boolean
Loop through all the record parts to check if at least one part changed.
245 246 247 |
# File 'lib/whois/parser.rb', line 245 def changed?(other) !unchanged?(other) end |
#contacts ⇒ Array<Whois::Record::Contact>
Collects and returns all the contacts from all the record parts.
227 228 229 |
# File 'lib/whois/parser.rb', line 227 def contacts parsers.map(&:contacts).flatten end |
#parsers ⇒ Array<Whois::Parsers::Base>
Returns an array with all host-specific parsers initialized for the parts contained into this parser. The array is lazy-initialized.
193 194 195 |
# File 'lib/whois/parser.rb', line 193 def parsers @parsers ||= init_parsers end |
#property_any_not_implemented?(property) ⇒ Boolean
Checks if the property
passed as symbol is “not implemented” in any of the parsers.
213 214 215 |
# File 'lib/whois/parser.rb', line 213 def property_any_not_implemented?(property) parsers.any? { |parser| parser.class.property_state?(property, Whois::Parser::PROPERTY_STATE_NOT_IMPLEMENTED) } end |
#property_any_supported?(property) ⇒ Boolean
Checks if the property
passed as symbol is supported in any of the parsers.
204 205 206 |
# File 'lib/whois/parser.rb', line 204 def property_any_supported?(property) parsers.any? { |parser| parser.property_supported?(property) } end |
#respond_to?(symbol, include_private = false) ⇒ Boolean
Checks if this class respond to given method.
Overrides the default implementation to add support for PROPERTIES and METHODS.
182 183 184 |
# File 'lib/whois/parser.rb', line 182 def respond_to?(symbol, include_private = false) respond_to_parser_method?(symbol) || super end |
#response_incomplete? ⇒ Boolean
Loop through all the parts to check if at least one part is an incomplete response.
275 276 277 |
# File 'lib/whois/parser.rb', line 275 def response_incomplete? any_is?(parsers, :response_incomplete?) end |
#response_throttled? ⇒ Boolean
Loop through all the parts to check if at least one part is a throttle response.
287 288 289 |
# File 'lib/whois/parser.rb', line 287 def response_throttled? any_is?(parsers, :response_throttled?) end |
#response_unavailable? ⇒ Boolean
Loop through all the parts to check if at least one part is an unavailable response.
299 300 301 |
# File 'lib/whois/parser.rb', line 299 def response_unavailable? any_is?(parsers, :response_unavailable?) end |
#unchanged?(other) ⇒ Boolean
The opposite of #changed?.
257 258 259 260 261 262 263 264 |
# File 'lib/whois/parser.rb', line 257 def unchanged?(other) unless other.is_a?(self.class) raise(ArgumentError, "Can't compare `#{self.class}' with `#{other.class}'") end equal?(other) || parsers.size == other.parsers.size && all_in_parallel?(parsers, other.parsers) { |one, two| one.unchanged?(two) } end |