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:



29
30
31
32
# File 'lib/whois/record.rb', line 29

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:



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

def parts
  @parts
end

#serverWhois::Server (readonly)

Returns The server that originated this record.

Returns:



18
19
20
# File 'lib/whois/record.rb', line 18

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)


57
58
59
60
61
62
63
64
65
# File 'lib/whois/record.rb', line 57

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.



110
111
112
# File 'lib/whois/record.rb', line 110

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.



47
48
49
# File 'lib/whois/record.rb', line 47

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


79
80
81
# File 'lib/whois/record.rb', line 79

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:



91
92
93
# File 'lib/whois/record.rb', line 91

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

#to_sString

Returns a String representation of this record.

Returns:

  • (String)

    The record content.



39
40
41
# File 'lib/whois/record.rb', line 39

def to_s
  content.to_s
end