Sha256: f0b7e4f587c0cb8c78939008e17ffb0d2b9f9ec42ac8b094ec765aec2a7b48e6

Contents?: true

Size: 1.3 KB

Versions: 4

Compression:

Stored size: 1.3 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

  
  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 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

4 entries across 4 versions & 1 rubygems

Version Path
ninoxe-1.1.5 app/models/chouette/time_table_period.rb
ninoxe-1.1.4 app/models/chouette/time_table_period.rb
ninoxe-1.1.3 app/models/chouette/time_table_period.rb
ninoxe-1.1.2 app/models/chouette/time_table_period.rb