Class: Whois::Record

Inherits:
Object
  • Object
show all
Defined in:
lib/whois/record.rb,
lib/whois/record/part.rb

Defined Under Namespace

Classes: Part

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(server, parts) ⇒ Record

Initializes a new instance with given server and parts.

Parameters:



32
33
34
35
# File 'lib/whois/record.rb', line 32

def initialize(server, parts)
  @parts  = parts
  @server = server
end

Instance Attribute Details

#partsArray<Whois::Record::Part> (readonly)

Returns The parts that compose this record.

Returns:



24
25
26
# File 'lib/whois/record.rb', line 24

def parts
  @parts
end

#serverWhois::Server (readonly)

Returns The server that originated this record.

Returns:



21
22
23
# File 'lib/whois/record.rb', line 21

def server
  @server
end

Instance Method Details

#==(other) ⇒ Boolean Also known as: eql?

Returns true if the object is the same object, or is a string and has the same content.

Parameters:

Returns:

  • (Boolean)


60
61
62
63
64
65
66
67
68
# File 'lib/whois/record.rb', line 60

def ==(other)
  if equal?(other)
    true
  elsif other.is_a?(self.class)
    to_s == other.to_s
  else
    false
  end
end

#contentString

Joins and returns all record parts into a single string and separates each response with a newline character.

Examples:

Record with one part

record = Whois::Record.new([Whois::Record::Part.new(:body => "First record.")])
record.content
# => "First record."

Record with multiple parts

record = Whois::Record.new([Whois::Record::Part.new(:body => "First record."), Whois::Record::Part.new(:body => "Second record.")])
record.content
# => "First record.\nSecond record."

Returns:

  • (String)

    The content of this record.



113
114
115
# File 'lib/whois/record.rb', line 113

def content
  @content ||= parts.map(&:body).join("\n")
end

#inspectString

Returns a human-readable representation of this record.

Returns:

  • (String)

    The result of #inspect on content.



50
51
52
# File 'lib/whois/record.rb', line 50

def inspect
  content.inspect
end

#match(pattern) ⇒ MatchData?

Invokes #match on record #content and returns the match as MatchData or nil.

Parameters:

  • pattern (Regexp, String)

    The regex pattern to match.

Returns:

  • (MatchData)

    If pattern matches #content

  • (nil)

    If pattern doesn’t match #content

See Also:

  • String#match


82
83
84
# File 'lib/whois/record.rb', line 82

def match(pattern)
  content.match(pattern)
end

#match?(pattern) ⇒ Boolean

Invokes #match and returns true if pattern matches #content, false otherwise.

Parameters:

  • pattern (Regexp, String)

    The regex pattern to match.

Returns:

  • (Boolean)

See Also:



94
95
96
# File 'lib/whois/record.rb', line 94

def match?(pattern)
  !content.match(pattern).nil?
end

#to_sString

Returns a String representation of this record.

Returns:

  • (String)

    The record content.



42
43
44
# File 'lib/whois/record.rb', line 42

def to_s
  content.to_s
end