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 |
# File 'lib/groupdate/magic.rb', line 7 def initialize(period:, **) @period = period @options = 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 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 @options 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
30 31 32 |
# File 'lib/groupdate/magic.rb', line 30 def day_start @day_start ||= (([:day_start] || Groupdate.day_start).to_f * 3600).round end |
#series_builder ⇒ Object
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/groupdate/magic.rb', line 34 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
45 46 47 |
# File 'lib/groupdate/magic.rb', line 45 def time_range series_builder.time_range end |
#time_zone ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/groupdate/magic.rb', line 18 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
26 27 28 |
# File 'lib/groupdate/magic.rb', line 26 def week_start @week_start ||= [:mon, :tue, :wed, :thu, :fri, :sat, :sun].index(([:week_start] || [:start] || Groupdate.week_start).to_sym) end |