Class: TimeOverlap::Calculator
- Inherits:
-
Object
- Object
- TimeOverlap::Calculator
- Defined in:
- lib/time_overlap.rb
Class Method Summary collapse
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(from:, to:, time_zone:, my_time_zone:, min_overlap:) ⇒ Calculator
constructor
TODO: add meeting time to choose overlap 1 or overlap 2.
Constructor Details
#initialize(from:, to:, time_zone:, my_time_zone:, min_overlap:) ⇒ Calculator
TODO: add meeting time to choose overlap 1 or overlap 2
12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/time_overlap.rb', line 12 def initialize(from:, to:, time_zone:, my_time_zone:, min_overlap:) @current_year = Time.current.year @current_month = Time.current.month @current_day = Time.current.day @from = from @to = to @time_zone = time_zone @my_time_zone = my_time_zone @min_overlap = min_overlap @duration = (end_time - start_time).to_i / 60 / 60 @data = {} end |
Class Method Details
.count(*args) ⇒ Object
27 28 29 |
# File 'lib/time_overlap.rb', line 27 def self.count(*args) self.new(*args).execute end |
Instance Method Details
#execute ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/time_overlap.rb', line 31 def execute offset = duration - min_overlap start_time_in_my_time_zone = start_time.in_time_zone(my_time_zone) end_time_in_my_time_zone = end_time.in_time_zone(my_time_zone) x_start_time = (start_time - offset * 60 * 60).in_time_zone(my_time_zone) x_end_time = (end_time - offset * 60 * 60).in_time_zone(my_time_zone) y_start_time = (end_time - min_overlap * 60 * 60).in_time_zone(my_time_zone) y_end_time = (y_start_time + duration * 60 * 60).in_time_zone(my_time_zone) @data = { original: { start: start_time, end: end_time }, full_overlap: { start: start_time_in_my_time_zone, end: end_time_in_my_time_zone }, overlap_1: { start: x_start_time, end: x_end_time }, overlap_2: { start: y_start_time, end: y_end_time } } check Presenter.new(@data).generate_output @data end |