Module: Auth::Concerns::Shopping::ProductConcern::ClassMethods
- Defined in:
- app/models/auth/concerns/shopping/product_concern.rb
Instance Method Summary collapse
-
#add_to_previous_rolling_n_minutes(minutes, origin_epoch, cycle_to_add) ⇒ Object
so we have completed the rolling n minutes.
-
#schedule_cycles(minutes, location_id, conditions = {}) ⇒ Object
minutes : => minute object.
Instance Method Details
#add_to_previous_rolling_n_minutes(minutes, origin_epoch, cycle_to_add) ⇒ Object
so we have completed the rolling n minutes.
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'app/models/auth/concerns/shopping/product_concern.rb', line 130 def add_to_previous_rolling_n_minutes(minutes,origin_epoch,cycle_to_add) ## get all the minutes less than that. rolling_n_minutes_less_than_that = minutes.keys.select{|c| c < origin_epoch} end_min = rolling_n_minutes_less_than_that.size < Auth.configuration.rolling_minutes ? rolling_n_minutes_less_than_that.size : Auth.configuration.rolling_minutes end_min = end_min - 1 end_min = end_min > 0 ? end_min : 0 rolling_n_minutes_less_than_that[0..end_min].each do |epoch| minutes[epoch].cycles << cycle_to_add end end |
#schedule_cycles(minutes, location_id, conditions = {}) ⇒ Object
minutes : => minute object
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 |
# File 'app/models/auth/concerns/shopping/product_concern.rb', line 147 def schedule_cycles(minutes,location_id,conditions = {}) products = Auth.configuration.product_class.constantize.all if conditions.blank? products = Auth.configuration.product_class.constantize.where(conditions) if !conditions.blank? minutes.keys.each do |epoch| products.each do |product| all_cycles_valid = true product.cycles.each do |cycle| all_cycles_valid = cycle.requirements_satisfied(epoch + cycle.time_since_prev_cycle.minutes*60,location_id) end if all_cycles_valid == true cycle_chain = [] product.cycles.each do |cycle| epoch_at_which_to_add = epoch + cycle.time_since_prev_cycle.minutes*60 cycle_to_add = cycle.dup cycle_to_add.start_time = epoch_at_which_to_add cycle_to_add.end_time = cycle_to_add.start_time + cycle_to_add.duration cycle_to_add.cycle_chain = cycle_chain if minutes[epoch_at_which_to_add] add_to_previous_rolling_n_minutes(minutes,epoch_at_which_to_add,cycle_to_add) minutes[epoch_at_which_to_add].cycles << cycle_to_add cycle_chain << cycle_to_add.id.to_s else #raise "necessary minute not in range." end end end end end minutes end |