Sha256: c821a7edaa366ed71d1980d4649d0f5ce3454d06ecd4af9c64ba16d719a652ea

Contents?: true

Size: 1.64 KB

Versions: 2

Compression:

Stored size: 1.64 KB

Contents

class Show < ActiveRecord::Base
  include Extensions::UUID
	
  has_many :show_sets, :foreign_key => :show_uuid, :primary_key => :uuid
  has_many :song_occurences, :foreign_key => :show_uuid, :primary_key => :uuid
  has_many :song_refs, :through => :song_occurences, :foreign_key => :show_uuid

  def self.create_from(spec)
    show = Show.new
    set_spec(show, spec)
    show.save
    show
  end

  def self.update_from(spec)
    show = Show.find_by(uuid: spec[:uuid])
    set_spec(show, spec)
    show.save
    show
  end
  
  def self.remove_from(spec)
    show = Show.find_by_uuid(spec[:uuid])
    show.delete if show
  end

  def self.parse_date(readable_date)
    parsed = readable_date.split('/')
    date_hash = {year: parsed[0].to_i, month: parsed[1].to_i, day: parsed[2].to_i}
    if(parsed.length == 4)
      date_hash[:position] = parsed[3].to_i
    end
    date_hash
  end

  def date_string(separator = "/")
    date_string = "#{year}#{separator}#{pad month}#{separator}#{pad day}"
    date_string = "#{date_string}/#{position}" if position
    date_string
  end

  def date_identifier
    if(position)
      date_string + "/#{position}"
    else
      date_string
    end
  end

  def title
    "#{date_string} #{venue}, #{city}, #{state}, #{country}"
  end
  
  def to_s
   title
  end  

  private 

  def self.set_spec(show, spec) 
    show.uuid = spec[:uuid]
    show.venue = spec[:venue]
    show.city = spec[:city]
    show.state = spec[:state]
    show.country = spec[:country]
    show.year = spec[:year]
    show.month = spec[:month]
    show.day = spec[:day]
    show.position = spec[:position]
    show
  end

  def pad(int)
    "%02d" % int
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
gdshowsdb-4.0.1 lib/gdshowsdb/models/show.rb
gdshowsdb-4.0.0 lib/gdshowsdb/models/show.rb