Class: Flycal::Mock::SlotScenario
- Inherits:
-
Object
- Object
- Flycal::Mock::SlotScenario
- Defined in:
- lib/flycal/mock/slot_scenario.rb
Overview
Generates mock busy events, then computes the free slots those events imply.
Constant Summary collapse
- DEFAULT_MOCK =
{ mockCalendar: "mock-calendar", mockEventCount: 8, mockEventFrom: "2026-08-24", mockEventTo: "2026-08-28", mockEventDurationMin: "30m", mockEventDurationMax: "90m", mockEventHoursFrom: "09:00", mockEventHoursTo: "20:00", mockEventDescriptionPatterns: "standup,review" }.freeze
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#events ⇒ Object
readonly
Returns the value of attribute events.
-
#expected_count ⇒ Object
readonly
Returns the value of attribute expected_count.
-
#query ⇒ Object
readonly
Returns the value of attribute query.
-
#seed ⇒ Object
readonly
Returns the value of attribute seed.
-
#slots_by_day ⇒ Object
readonly
Returns the value of attribute slots_by_day.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(mock: {}, slots: {}) ⇒ SlotScenario
constructor
A new instance of SlotScenario.
- #to_h ⇒ Object
Constructor Details
#initialize(mock: {}, slots: {}) ⇒ SlotScenario
Returns a new instance of SlotScenario.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/flycal/mock/slot_scenario.rb', line 25 def initialize(mock: {}, slots: {}) mock_opts = DEFAULT_MOCK.merge(symbolize(mock)) @seed = Integer(mock_opts[:mockSeed] || (Random.new_seed & 0xFFFFFFFF)) mock_opts[:mockSeed] = @seed @config = Config.(mock_opts) timezone = TimeFormat.resolve(explicit: slots[:timezone] || slots["timezone"]) TimeFormat.with_zone(timezone) do @events = EventGenerator.new(@config).generate @query = SlotQuery.resolve( { calendar_ids: [ @config.calendar_name ], timezone: timezone }.merge(symbolize(slots)) ) finder = SlotFinder.new( events: @events, time_min: @query[:time_min], time_max: @query[:time_max], slot_duration_seconds: @query[:slot_duration_seconds], hours: @query[:hours], days: @query[:days], free_before_seconds: @query[:free_before_seconds], free_after_seconds: @query[:free_after_seconds] ) @slots_by_day = finder.slots_by_day @expected_count = @slots_by_day.values.sum(&:size) end end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
19 20 21 |
# File 'lib/flycal/mock/slot_scenario.rb', line 19 def config @config end |
#events ⇒ Object (readonly)
Returns the value of attribute events.
19 20 21 |
# File 'lib/flycal/mock/slot_scenario.rb', line 19 def events @events end |
#expected_count ⇒ Object (readonly)
Returns the value of attribute expected_count.
19 20 21 |
# File 'lib/flycal/mock/slot_scenario.rb', line 19 def expected_count @expected_count end |
#query ⇒ Object (readonly)
Returns the value of attribute query.
19 20 21 |
# File 'lib/flycal/mock/slot_scenario.rb', line 19 def query @query end |
#seed ⇒ Object (readonly)
Returns the value of attribute seed.
19 20 21 |
# File 'lib/flycal/mock/slot_scenario.rb', line 19 def seed @seed end |
#slots_by_day ⇒ Object (readonly)
Returns the value of attribute slots_by_day.
19 20 21 |
# File 'lib/flycal/mock/slot_scenario.rb', line 19 def slots_by_day @slots_by_day end |
Class Method Details
.generate(mock: {}, slots: {}) ⇒ Object
21 22 23 |
# File 'lib/flycal/mock/slot_scenario.rb', line 21 def self.generate(mock: {}, slots: {}) new(mock: mock, slots: slots) end |
Instance Method Details
#to_h ⇒ Object
52 53 54 55 56 57 58 59 |
# File 'lib/flycal/mock/slot_scenario.rb', line 52 def to_h { seed: seed, expected_count: expected_count, events: events.map { |event| serialize_event(event) }, slots_by_day: slots_by_day } end |