Class: Groupdate::Magic
- Inherits:
-
Object
- Object
- Groupdate::Magic
- Defined in:
- lib/groupdate/magic.rb
Direct Known Subclasses
Defined Under Namespace
Classes: Enumerable, Relation
Instance Attribute Summary collapse
-
#group_index ⇒ Object
Returns the value of attribute group_index.
-
#options ⇒ Object
Returns the value of attribute options.
-
#period ⇒ Object
Returns the value of attribute period.
Instance Method Summary collapse
- #day_start ⇒ Object
-
#initialize(period:, **options) ⇒ Magic
constructor
A new instance of Magic.
- #series_builder ⇒ Object
- #time_range ⇒ Object
- #time_zone ⇒ Object
- #week_start ⇒ Object
Constructor Details
#initialize(period:, **options) ⇒ Magic
Returns a new instance of Magic.
7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/groupdate/magic.rb', line 7 def initialize(period:, **) @period = period = unknown_keywords = .keys - [:day_start, :time_zone, :dates, :series, :week_start, :format, :locale, :range, :reverse] raise ArgumentError, "unknown keywords: #{unknown_keywords.join(", ")}" if unknown_keywords.any? raise Groupdate::Error, "Unrecognized time zone" unless time_zone raise Groupdate::Error, "Unrecognized :week_start option" if period == :week && !week_start raise Groupdate::Error, "Cannot use endless range for :range option" if [:range].is_a?(Range) && ![:range].end end |
Instance Attribute Details
#group_index ⇒ Object
Returns the value of attribute group_index.
5 6 7 |
# File 'lib/groupdate/magic.rb', line 5 def group_index @group_index end |
#options ⇒ Object
Returns the value of attribute options.
5 6 7 |
# File 'lib/groupdate/magic.rb', line 5 def end |
#period ⇒ Object
Returns the value of attribute period.
5 6 7 |
# File 'lib/groupdate/magic.rb', line 5 def period @period end |
Instance Method Details
#day_start ⇒ Object
31 32 33 |
# File 'lib/groupdate/magic.rb', line 31 def day_start @day_start ||= (([:day_start] || Groupdate.day_start).to_f * 3600).round end |
#series_builder ⇒ Object
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/groupdate/magic.rb', line 35 def series_builder @series_builder ||= SeriesBuilder.new( **, period: period, time_zone: time_zone, day_start: day_start, week_start: week_start ) end |
#time_range ⇒ Object
46 47 48 |
# File 'lib/groupdate/magic.rb', line 46 def time_range series_builder.time_range end |
#time_zone ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/groupdate/magic.rb', line 19 def time_zone @time_zone ||= begin time_zone = "Etc/UTC" if [:time_zone] == false time_zone ||= [:time_zone] || Groupdate.time_zone || (Groupdate.time_zone == false && "Etc/UTC") || Time.zone || "Etc/UTC" time_zone.is_a?(ActiveSupport::TimeZone) ? time_zone : ActiveSupport::TimeZone[time_zone] end end |
#week_start ⇒ Object
27 28 29 |
# File 'lib/groupdate/magic.rb', line 27 def week_start @week_start ||= [:mon, :tue, :wed, :thu, :fri, :sat, :sun].index(([:week_start] || [:start] || Groupdate.week_start).to_sym) end |