Class: Aenea::TimeWindow
- Inherits:
-
Object
- Object
- Aenea::TimeWindow
- Defined in:
- lib/aenea/time_window.rb
Defined Under Namespace
Classes: Type
Constant Summary collapse
- SEPARATOR =
' - '
Instance Attribute Summary collapse
-
#ending ⇒ Object
readonly
Returns the value of attribute ending.
-
#starting ⇒ Object
readonly
Returns the value of attribute starting.
Class Method Summary collapse
- .parse(str) ⇒ Object
-
.parse_tuple(str) ⇒ Object
a row of PL/pgsql return type table(time, time), returned as a varchar using SELECT func_…
Instance Method Summary collapse
- #<=>(obj) ⇒ Object
- #==(obj) ⇒ Object
-
#initialize(start_tod, end_tod_or_window_in_seconds) ⇒ TimeWindow
constructor
A new instance of TimeWindow.
- #inspect ⇒ Object
- #to_ampm ⇒ Object
- #to_s ⇒ Object
- #to_select_value ⇒ Object
Constructor Details
#initialize(start_tod, end_tod_or_window_in_seconds) ⇒ TimeWindow
Returns a new instance of TimeWindow.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/aenea/time_window.rb', line 7 def initialize(start_tod, end_tod_or_window_in_seconds) @starting = start_tod.dup if end_tod_or_window_in_seconds.is_a?(Tod::TimeOfDay) @ending = end_tod_or_window_in_seconds.dup else @ending = @starting + end_tod_or_window_in_seconds # number of seconds end if ending < starting raise ArgumentError.new("invalid window #{starting} - #{ending}") end self.freeze end |
Instance Attribute Details
#ending ⇒ Object (readonly)
Returns the value of attribute ending.
5 6 7 |
# File 'lib/aenea/time_window.rb', line 5 def ending @ending end |
#starting ⇒ Object (readonly)
Returns the value of attribute starting.
5 6 7 |
# File 'lib/aenea/time_window.rb', line 5 def starting @starting end |
Class Method Details
.parse(str) ⇒ Object
23 24 25 |
# File 'lib/aenea/time_window.rb', line 23 def self.parse(str) new(*str.split(SEPARATOR).collect {|s| Tod::TimeOfDay.parse(s) }) end |
.parse_tuple(str) ⇒ Object
a row of PL/pgsql return type table(time, time), returned as a varchar using SELECT func_… rather than SELECT * FROM func_… - the returned values are in the form “(11:00:00,13:00:00)”
30 31 32 33 |
# File 'lib/aenea/time_window.rb', line 30 def self.parse_tuple(str) elements = str.sub(/^\(/, '').sub(/\)$/, '').split(',') new(*elements.map {|s| Tod::TimeOfDay.parse(s) }) end |
Instance Method Details
#<=>(obj) ⇒ Object
39 40 41 42 43 44 |
# File 'lib/aenea/time_window.rb', line 39 def <=>(obj) start_comp = self.starting <=> obj.starting return start_comp if start_comp != 0 self.ending <=> obj.ending end |
#==(obj) ⇒ Object
35 36 37 |
# File 'lib/aenea/time_window.rb', line 35 def ==(obj) self.starting == obj.starting && ending == obj.ending end |
#inspect ⇒ Object
58 59 60 |
# File 'lib/aenea/time_window.rb', line 58 def inspect "<#{to_s}>" end |
#to_ampm ⇒ Object
50 51 52 |
# File 'lib/aenea/time_window.rb', line 50 def to_ampm starting.to_ampm + SEPARATOR + ending.to_ampm end |
#to_s ⇒ Object
46 47 48 |
# File 'lib/aenea/time_window.rb', line 46 def to_s starting.to_s + SEPARATOR + ending.to_s end |
#to_select_value ⇒ Object
54 55 56 |
# File 'lib/aenea/time_window.rb', line 54 def to_select_value [to_ampm, to_s] end |