Class: Ping::Size

Inherits:
Object
  • Object
show all
Defined in:
lib/ping/size.rb

Constant Summary collapse

Pattern =
/
  (?:^|\W)             # beginning of string or non-word char
  (?:size|points):     # keyword
  (\d+)                # point value
  (?=
    \.+[ \t\W]|        # dots followed by space or non-word character
    \.+$|              # dots at end of line
    [^0-9a-zA-Z_.]|    # non-word character except dot
    $                  # end of line
  )
/ix

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(points) ⇒ Size



24
25
26
# File 'lib/ping/size.rb', line 24

def initialize(points)
  @points = points
end

Instance Attribute Details

#pointsObject

Returns the value of attribute points.



3
4
5
# File 'lib/ping/size.rb', line 3

def points
  @points
end

Class Method Details

.extract(text) ⇒ Object



19
20
21
22
# File 'lib/ping/size.rb', line 19

def self.extract(text)
  matches = text.scan(Pattern)
  matches.any? ? self.new(matches.last.first.to_i) : self.new(nil)
end

Instance Method Details

#==(other) ⇒ Object



28
29
30
# File 'lib/ping/size.rb', line 28

def ==(other)
  other.to_i == to_i
end

#to_iObject



32
33
34
# File 'lib/ping/size.rb', line 32

def to_i
  points.to_i
end

#to_sObject



36
37
38
# File 'lib/ping/size.rb', line 36

def to_s
  points.to_s
end