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.
"2.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}
. -
.bug!(error, message) ⇒ void
private
Appends ‘Please report issue to` to the message and raises a new
error
with the final message. -
.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
.
187 188 189 |
# File 'lib/whois/parser.rb', line 187 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)
345 346 347 348 349 350 351 352 353 354 355 |
# File 'lib/whois/parser.rb', line 345 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.
180 181 182 |
# File 'lib/whois/parser.rb', line 180 def record @record end |
Class Method Details
.autoload(name) ⇒ void
This method returns an undefined value.
Requires the file at whois/parsers/#{name}
.
174 175 176 |
# File 'lib/whois/parser.rb', line 174 def self.autoload(name) require "whois/parsers/#{name}" end |
.bug!(error, message) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Appends ‘Please report issue to` to the message and raises a new error
with the final message.
66 67 68 69 70 |
# File 'lib/whois/parser.rb', line 66 def self.bug!(error, ) raise error, .dup + " Please report the issue at" + " http://github.com/weppos/whois-parser/issues" end |
.host_to_parser(host) ⇒ String
Converts host
to the corresponding parser class name.
161 162 163 164 165 166 |
# File 'lib/whois/parser.rb', line 161 def self.host_to_parser(host) host.to_s.downcase .gsub(/[.-]/, '_') .gsub(/(?:^|_)(.)/) { ::Regexp.last_match(1).upcase } .gsub(/\A(\d+)\z/) { "Host#{::Regexp.last_match(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
.
114 115 116 117 118 119 |
# File 'lib/whois/parser.rb', line 114 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.
142 143 144 145 146 |
# File 'lib/whois/parser.rb', line 142 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.
260 261 262 |
# File 'lib/whois/parser.rb', line 260 def changed?(other) !unchanged?(other) end |
#contacts ⇒ Array<Whois::Record::Contact>
Collects and returns all the contacts from all the record parts.
242 243 244 |
# File 'lib/whois/parser.rb', line 242 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.
208 209 210 |
# File 'lib/whois/parser.rb', line 208 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.
228 229 230 |
# File 'lib/whois/parser.rb', line 228 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.
219 220 221 |
# File 'lib/whois/parser.rb', line 219 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.
197 198 199 |
# File 'lib/whois/parser.rb', line 197 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.
290 291 292 |
# File 'lib/whois/parser.rb', line 290 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.
302 303 304 |
# File 'lib/whois/parser.rb', line 302 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.
314 315 316 |
# File 'lib/whois/parser.rb', line 314 def response_unavailable? any_is?(parsers, :response_unavailable?) end |
#unchanged?(other) ⇒ Boolean
The opposite of #changed?.
272 273 274 275 276 277 278 279 |
# File 'lib/whois/parser.rb', line 272 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 |