Sha256: cfe319681018392f157aa5151edf6f944227a419b9ec1f8cc48d83ee1d47415b

Contents?: true

Size: 1.39 KB

Versions: 2

Compression:

Stored size: 1.39 KB

Contents

class Chouette::TimeTablePeriod < Chouette::ActiveRecord
  self.primary_key = "id"
  belongs_to :time_table, inverse_of: :periods
  acts_as_list :scope => 'time_table_id = #{time_table_id}',:top_of_list => 0

  attr_accessible :period_start, :period_end, :position,:time_table_id,:time_table
  
  validates_presence_of :period_start
  validates_presence_of :period_end
  
  validate :start_must_be_before_end

  after_update :update_parent
  
  def self.model_name
    ActiveModel::Name.new Chouette::TimeTablePeriod, Chouette, "TimeTablePeriod"
  end
  
  def start_must_be_before_end
    # security against nil values
    if period_end.nil? || period_start.nil?
      return
    end
    if period_end <= period_start
      errors.add(:period_end,I18n.t("activerecord.errors.models.time_table_period.start_must_be_before_end"))
    end
  end
  
  def update_parent
    time_table.shortcuts_update
  end
  
  def copy
    Chouette::TimeTablePeriod.new(:period_start => self.period_start,:period_end => self.period_end)
  end
  
  # Test to see if a period overlap this period
  def overlap?(p)
     (p.period_start >= self.period_start && p.period_start <= self.period_end) || (p.period_end >= self.period_start && p.period_end <= self.period_end)
  end

  # Test to see if a period is included in this period
  def contains?(p)
     (p.period_start >= self.period_start && p.period_end <= self.period_end)
  end
  
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ninoxe-1.1.1 app/models/chouette/time_table_period.rb
ninoxe-1.1.0 app/models/chouette/time_table_period.rb