class Timely::Season

Public Instance Methods

audit_name()
Alias for: to_s
boundary_end() click to toggle source
# File lib/timely/rails/season.rb, line 40
def boundary_end
  date_groups.map(&:end_date).max
end
boundary_range() click to toggle source
# File lib/timely/rails/season.rb, line 28
def boundary_range
  boundary_start..boundary_end
end
boundary_start() click to toggle source
# File lib/timely/rails/season.rb, line 36
def boundary_start
  date_groups.map(&:start_date).min
end
dates() click to toggle source
# File lib/timely/rails/season.rb, line 22
def dates
  date_groups.map do |date_group|
    ((date_group.start_date)..(date_group.end_date)).to_a
  end.flatten
end
deep_clone() click to toggle source
# File lib/timely/rails/season.rb, line 48
def deep_clone
  # Use clone until it is removed in AR 3.1, then dup is the same
  method = ActiveRecord::Base.instance_methods(false).include?(:clone) ? :clone : :dup
  cloned = send(method)
  date_groups.each do |dg|
    cloned.date_groups.build(dg.send(method).attributes)
  end
  cloned
end
includes_date?(date) click to toggle source
# File lib/timely/rails/season.rb, line 18
def includes_date?(date)
  date_groups.any? { |dg| dg.includes_date?(date) }
end
past?() click to toggle source
# File lib/timely/rails/season.rb, line 32
def past?
  boundary_end && boundary_end < ::Date.current
end
string_of_date_groups() click to toggle source
# File lib/timely/rails/season.rb, line 64
def string_of_date_groups
  date_groups.map  do |dg|
    "#{dg.start_date.to_s(:short)} - #{dg.end_date.to_s(:short)}"
  end.to_sentence
end
to_s() click to toggle source
# File lib/timely/rails/season.rb, line 58
def to_s
  name.presence || Timely::DateRange.to_s(boundary_start, boundary_end)
end
Also aliased as: audit_name
validate_dates_specified() click to toggle source
# File lib/timely/rails/season.rb, line 13
def validate_dates_specified
  errors.add(:base, 'No dates specified') if date_groups.blank?
  errors.empty?
end
within_boundary?(date) click to toggle source
# File lib/timely/rails/season.rb, line 44
def within_boundary?(date)
  boundary_start && boundary_end && boundary_start <= date && boundary_end >= date
end