Sha256: 551a3291245cb168536140ce9e78c20d08e16622e931aa330be121708cdd2355

Contents?: true

Size: 1.03 KB

Versions: 2

Compression:

Stored size: 1.03 KB

Contents

module OpenConferenceWare

  # == Schema Information
  #
  # Table name: tracks
  #
  #  id          :integer          not null, primary key
  #  title       :string(255)
  #  description :text
  #  color       :string(255)
  #  event_id    :integer
  #  created_at  :datetime
  #  updated_at  :datetime
  #  excerpt     :text
  #

  class Track < OpenConferenceWare::Base

    # Associations
    belongs_to :event
    has_many :proposals, dependent: :nullify

    # Validations
    validates_presence_of \
      :color,
      :description,
      :excerpt,
      :event_id,
      :title

    def <=>(against)
      self.title <=> (against.nil? ? '' : against.title)
    end

    def color
      (stored_color = read_attribute(:color)).nil? ? nil : Color::RGB.from_html(stored_color)
    end

    def color=(value)
      case value
      when Color::RGB
        new_color = value
      when String
        new_color = Color::RGB.from_html(value)
      else
        raise TypeError
      end
      write_attribute(:color,new_color.html)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
open_conference_ware-1.0.0.pre3 app/models/open_conference_ware/track.rb
open_conference_ware-1.0.0.pre2 app/models/open_conference_ware/track.rb