Class: Periodoxical::Core
- Inherits:
-
Object
- Object
- Periodoxical::Core
- Includes:
- Helpers, Validation
- Defined in:
- lib/periodoxical.rb
Constant Summary
Constants included from Validation
Validation::VALID_DAYS_OF_WEEK
Instance Method Summary collapse
-
#generate ⇒ Array<Hash<DateTime>>
Ex: [ { start: #<DateTime>, end: #<DateTime>, }, { start: #<DateTime>, end: #<DateTime>, }, ].
-
#initialize(starting_from:, ending_at: nil, time_blocks: nil, day_of_week_time_blocks: nil, limit: nil, exclusion_dates: nil, exclusion_times: nil, time_zone: 'Etc/UTC', days_of_week: nil, nth_day_of_week_in_month: nil, days_of_month: nil, duration: nil, months: nil) ⇒ Core
constructor
A new instance of Core.
Methods included from Helpers
#date_object_from, #day_of_week_long_to_short, #deep_symbolize_keys, #overlap?
Methods included from Validation
Constructor Details
#initialize(starting_from:, ending_at: nil, time_blocks: nil, day_of_week_time_blocks: nil, limit: nil, exclusion_dates: nil, exclusion_times: nil, time_zone: 'Etc/UTC', days_of_week: nil, nth_day_of_week_in_month: nil, days_of_month: nil, duration: nil, months: nil) ⇒ Core
Returns a new instance of Core.
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/periodoxical.rb', line 74 def initialize( starting_from:, ending_at: nil, time_blocks: nil, day_of_week_time_blocks: nil, limit: nil, exclusion_dates: nil, exclusion_times: nil, time_zone: 'Etc/UTC', days_of_week: nil, nth_day_of_week_in_month: nil, days_of_month: nil, duration: nil, months: nil ) @time_zone = TZInfo::Timezone.get(time_zone) if days_of_week.is_a?(Array) @days_of_week = deep_symbolize_keys(days_of_week) elsif days_of_week.is_a?(Hash) @days_of_week_with_alternations = deep_symbolize_keys(days_of_week) end @nth_day_of_week_in_month = deep_symbolize_keys(nth_day_of_week_in_month) @days_of_month = days_of_month @months = months @time_blocks = deep_symbolize_keys(time_blocks) @day_of_week_time_blocks = deep_symbolize_keys(day_of_week_time_blocks) @starting_from = date_object_from(starting_from) @ending_at = date_object_from(ending_at) @limit = limit if duration unless duration.is_a?(Integer) raise "duration must be an integer" else @duration = duration end end @exclusion_dates = if exclusion_dates && !exclusion_dates.empty? exclusion_dates.map { |ed| Date.parse(ed) } end @exclusion_times = if exclusion_times deep_symbolize_keys(exclusion_times).map do |et| { start: DateTime.parse(et[:start]), end: DateTime.parse(et[:end]) } end end validate! end |
Instance Method Details
#generate ⇒ Array<Hash<DateTime>>
Returns Ex: [
{
start: #<DateTime>,
end: #<DateTime>,
},
{
start: #<DateTime>,
end: #<DateTime>,
},
].
134 135 136 137 138 139 140 141 142 143 |
# File 'lib/periodoxical.rb', line 134 def generate initialize_looping_variables! while @keep_generating if should_add_time_blocks_from_current_date? add_time_blocks_from_current_date! end advance_current_date_and_check_if_reached_end_date end @output end |