-
-
Save aaronmoodie/5401127 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Show < ActiveRecord::Base | |
attr_accessible :artist_tokens, :cost, :booking_url, :door_charge, :venue_id, :date, :time, :starts_at | |
attr_reader :artist_tokens, :date, :time | |
validate :is_time | |
validate :is_date | |
before_save :save_date_and_time | |
has_many :performances | |
has_many :artists, :through => :performances | |
belongs_to :user | |
belongs_to :venue | |
def artist_tokens=(tokens) | |
self.artist_ids = Artist.ids_from_tokens(tokens) | |
end | |
def date | |
if @date | |
@date | |
else | |
starts_at ? starts_at.in_time_zone(Venue.get_venue_timezone(self.venue_id)).strftime("%A, %B #{starts_at.day.ordinalize}") : "" | |
end | |
end | |
def date=(d) | |
@date = d | |
end | |
def time | |
if @time | |
@time | |
else | |
starts_at ? starts_at.in_time_zone(Venue.get_venue_timezone(self.venue_id)).strftime("%l:%M %p") : "" | |
end | |
end | |
def time=(t) | |
@time = t | |
end | |
private | |
def is_time | |
errors.add(:time, 'must be a valid time') if ((DateTime.parse(@time) rescue ArgumentError) == ArgumentError) | |
end | |
def is_date | |
errors.add(:date, 'must be a valid date') if ((DateTime.parse(@date) rescue ArgumentError) == ArgumentError) | |
end | |
def save_date_and_time | |
time_zone = Venue.get_venue_timezone(venue_id) | |
self.starts_at = ActiveSupport::TimeZone[time_zone].parse(@date + " " + @time) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Line 36 should probably use the instance variables, rather than the getter method:
starts_at = Chronic.parse(@date + @time)