Class: Comee::Core::Period
- Inherits:
-
Object
- Object
- Comee::Core::Period
- Defined in:
- app/utils/comee/core/period.rb
Instance Attribute Summary collapse
-
#finish ⇒ Object
Returns the value of attribute finish.
-
#start ⇒ Object
Returns the value of attribute start.
Class Method Summary collapse
Instance Method Summary collapse
- #<(other) ⇒ Object
- #==(other) ⇒ Object
- #>(other) ⇒ Object
- #contained_by?(period) ⇒ Boolean
- #contains?(period) ⇒ Boolean
- #current? ⇒ Boolean
- #disjoint?(period) ⇒ Boolean
- #future? ⇒ Boolean
-
#initialize(start, finish) ⇒ Period
constructor
A new instance of Period.
- #overlaps?(period) ⇒ Boolean
- #past? ⇒ Boolean
- #valid? ⇒ Boolean
Constructor Details
#initialize(start, finish) ⇒ Period
Returns a new instance of Period.
6 7 8 9 |
# File 'app/utils/comee/core/period.rb', line 6 def initialize(start, finish) @start = start @finish = finish end |
Instance Attribute Details
#finish ⇒ Object
Returns the value of attribute finish.
4 5 6 |
# File 'app/utils/comee/core/period.rb', line 4 def finish @finish end |
#start ⇒ Object
Returns the value of attribute start.
4 5 6 |
# File 'app/utils/comee/core/period.rb', line 4 def start @start end |
Class Method Details
.compute_next_valid_period(period1, period2) ⇒ Object
69 70 71 72 73 74 75 76 77 78 |
# File 'app/utils/comee/core/period.rb', line 69 def self.compute_next_valid_period(period1, period2) return period2 if period1.disjoint?(period2) && period1 < period2 return nil if period1 > period2 || period1.contains?(period2) period = Period.new(period1.finish.advance(days: 1), period2.finish) return nil unless period.valid? period end |
Instance Method Details
#<(other) ⇒ Object
15 16 17 |
# File 'app/utils/comee/core/period.rb', line 15 def <(other) instance_of?(other.class) && @start < other.start && @finish < other.finish end |
#==(other) ⇒ Object
11 12 13 |
# File 'app/utils/comee/core/period.rb', line 11 def ==(other) self.class == other.class && @start == other.start && @finish == other.finish end |
#>(other) ⇒ Object
19 20 21 |
# File 'app/utils/comee/core/period.rb', line 19 def >(other) instance_of?(other.class) && @start > other.start && @finish > other.finish end |
#contained_by?(period) ⇒ Boolean
51 52 53 54 55 |
# File 'app/utils/comee/core/period.rb', line 51 def contained_by?(period) return true if start >= period.start && finish <= period.finish false end |
#contains?(period) ⇒ Boolean
45 46 47 48 49 |
# File 'app/utils/comee/core/period.rb', line 45 def contains?(period) return true if start <= period.start && finish >= period.finish false end |
#current? ⇒ Boolean
33 34 35 36 37 |
# File 'app/utils/comee/core/period.rb', line 33 def current? raise(StandardError, "Period must be valid.") unless valid? start <= Date.current && finish > Date.current end |
#disjoint?(period) ⇒ Boolean
57 58 59 |
# File 'app/utils/comee/core/period.rb', line 57 def disjoint?(period) @finish < period.start || period.finish < @start end |
#future? ⇒ Boolean
39 40 41 42 43 |
# File 'app/utils/comee/core/period.rb', line 39 def future? raise(StandardError, "Period must be valid.") unless valid? start > Date.current end |
#overlaps?(period) ⇒ Boolean
61 62 63 64 65 66 67 |
# File 'app/utils/comee/core/period.rb', line 61 def overlaps?(period) return true if period.start <= @start && @start <= period.finish return true if @start <= period.start && period.start <= @finish false end |
#past? ⇒ Boolean
27 28 29 30 31 |
# File 'app/utils/comee/core/period.rb', line 27 def past? raise(StandardError, "Period must be valid.") unless valid? finish < Date.current end |
#valid? ⇒ Boolean
23 24 25 |
# File 'app/utils/comee/core/period.rb', line 23 def valid? finish > start end |