Class: TimespanRange

Inherits:
DelegateDecorator
  • Object
show all
Defined in:
lib/timespan/core_ext/range.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(range, unit = :minutes) ⇒ TimespanRange

Returns a new instance of TimespanRange.



4
5
6
7
8
9
# File 'lib/timespan/core_ext/range.rb', line 4

def initialize range, unit = :minutes
  range = (0..60) if range.min == nil || range.max == nil
  super(range, except: %w{to_s to_str})
  @range = Timespan.new between: range
  @unit = unit.to_s.pluralize.to_sym
end

Instance Attribute Details

#rangeObject

Returns the value of attribute range.



2
3
4
# File 'lib/timespan/core_ext/range.rb', line 2

def range
  @range
end

#unitObject

Returns the value of attribute unit.



2
3
4
# File 'lib/timespan/core_ext/range.rb', line 2

def unit
  @unit
end

Instance Method Details

#to_sObject



15
16
17
# File 'lib/timespan/core_ext/range.rb', line 15

def to_s
  range.min.nil? ? 'no timespan range' : "#{range.min} to #{range.max} #{unit}"
end

#to_strObject



11
12
13
# File 'lib/timespan/core_ext/range.rb', line 11

def to_str
  to_s
end