Class: Webspicy::Support::StatusRange

Inherits:
Object
  • Object
show all
Defined in:
lib/webspicy/support/status_range.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(range) ⇒ StatusRange

Returns a new instance of StatusRange.



5
6
7
# File 'lib/webspicy/support/status_range.rb', line 5

def initialize(range)
  @range = range
end

Instance Attribute Details

#rangeObject (readonly)

Returns the value of attribute range.



8
9
10
# File 'lib/webspicy/support/status_range.rb', line 8

def range
  @range
end

Class Method Details

.int(i) ⇒ Object



10
11
12
# File 'lib/webspicy/support/status_range.rb', line 10

def self.int(i)
  new(i..i)
end

.str(s) ⇒ Object



18
19
20
21
# File 'lib/webspicy/support/status_range.rb', line 18

def self.str(s)
  from = s[/^(\d)/,1].to_i * 100
  new(from...from+100)
end

Instance Method Details

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



35
36
37
# File 'lib/webspicy/support/status_range.rb', line 35

def ==(other)
  other.is_a?(StatusRange) && self.range == other.range
end

#===(status) ⇒ Object



31
32
33
# File 'lib/webspicy/support/status_range.rb', line 31

def ===(status)
  range === status
end

#hashObject



40
41
42
# File 'lib/webspicy/support/status_range.rb', line 40

def hash
  @range.hash
end

#to_iObject



27
28
29
# File 'lib/webspicy/support/status_range.rb', line 27

def to_i
  @range.first
end

#to_intObject



14
15
16
# File 'lib/webspicy/support/status_range.rb', line 14

def to_int
  @range.first
end

#to_sObject Also known as: inspect



44
45
46
47
48
49
50
# File 'lib/webspicy/support/status_range.rb', line 44

def to_s
  if @range.first == @range.last
    @range.first.to_s
  else
    @range.to_s
  end
end

#to_strObject



23
24
25
# File 'lib/webspicy/support/status_range.rb', line 23

def to_str
  "#{@range.first/100}xx"
end