Class: CalendarizeHelper::AbstractCalendarBuilder
- Inherits:
-
ActionView::Base
- Object
- ActionView::Base
- CalendarizeHelper::AbstractCalendarBuilder
- Defined in:
- app/helpers/calendarize_helper.rb
Direct Known Subclasses
Constant Summary collapse
- @@uuid =
100
Instance Attribute Summary collapse
-
#event ⇒ Object
readonly
Returns the value of attribute event.
-
#is_all_day ⇒ Object
readonly
Returns the value of attribute is_all_day.
Instance Method Summary collapse
- #compute ⇒ Object
-
#initialize(view_context, *args) ⇒ AbstractCalendarBuilder
constructor
A new instance of AbstractCalendarBuilder.
- #render ⇒ Object
Constructor Details
#initialize(view_context, *args) ⇒ AbstractCalendarBuilder
Returns a new instance of AbstractCalendarBuilder.
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 |
# File 'app/helpers/calendarize_helper.rb', line 179 def initialize(view_context, *args) opts = args. @view_context = view_context @options = { unit: 60, date_format: :long, url: @view_context.request.path, verbose: true, day_start: 0, day_end: 1440 }.merge!(opts) @day = args.shift || Date.today @events = args.shift || [] @event = nil # can be accessed by the passed block @is_all_day = false @@uuid += 1 end |
Instance Attribute Details
#event ⇒ Object (readonly)
Returns the value of attribute event.
176 177 178 |
# File 'app/helpers/calendarize_helper.rb', line 176 def event @event end |
#is_all_day ⇒ Object (readonly)
Returns the value of attribute is_all_day.
176 177 178 |
# File 'app/helpers/calendarize_helper.rb', line 176 def is_all_day @is_all_day end |
Instance Method Details
#compute ⇒ Object
202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 |
# File 'app/helpers/calendarize_helper.rb', line 202 def compute day_time = @day.to_datetime # Get the starting and the ending row of the calendar # :starting_row and :ending_row are in minutes so if :starting_row == 60 # and the :unit == 60, that means one row equals 1 hour and we start the # rows at hour 1. @_starting_row = @options[:day_start] / @options[:unit] @_ending_row = @options[:day_end] / @options[:unit] # Get the rows (in :datetime) # The indexes will be used as :ids in the rendering @rows = (@_starting_row...@_ending_row).to_a @rows_hours = @rows.map { |r| day_time + r * @options[:unit] / 1440.0 } # Sort the events in ascending order of their :start_time # Note: not done in-place the first time so the user can re-use it's collection @events = @events.sort { |e1, e2| e1.start_time <=> e2.start_time } self end |
#render ⇒ Object
225 226 227 |
# File 'app/helpers/calendarize_helper.rb', line 225 def render end |