Sha256: 4fc9db39b53ff34c851d393e040ec8dca1d98e6732a4e6d4aec4e6a307e7a768

Contents?: true

Size: 924 Bytes

Versions: 10

Compression:

Stored size: 924 Bytes

Contents

class AttributeType < ActiveRecord::Base
  has_many :attribute_values, :dependent => :destroy

  validates_uniqueness_of :internal_identifier
  validates :description, :presence => true

  before_save :update_iid

  def values_by_date_range(start_date, end_date)
    raise "attribute_type does not have a data_type of Date" unless self.data_type == "Date"
    
    attribute_values = self.attribute_values
    attribute_values.each do |attribute_value|
      unless attribute_value.value_as_date >= start_date and attribute_value.value_as_date <= end_date
        attribute_values.delete(attribute_value)
      end
    end

    attribute_values
  end

  def self.find_by_iid_with_description(description)
    iid = description.strip.underscore.gsub(/\s+/,"_")
    AttributeType.find_by_internal_identifier iid
  end

  def update_iid
    self.internal_identifier = self.description.strip.underscore.gsub(/\s+/,"_")
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
erp_tech_svcs-3.0.10 app/models/attribute_type.rb
erp_tech_svcs-3.0.9 app/models/attribute_type.rb
erp_tech_svcs-3.0.8 app/models/attribute_type.rb
erp_tech_svcs-3.0.7 app/models/attribute_type.rb
erp_tech_svcs-3.0.6 app/models/attribute_type.rb
erp_tech_svcs-3.0.5 app/models/attribute_type.rb
erp_tech_svcs-3.0.4 app/models/attribute_type.rb
erp_tech_svcs-3.0.3 app/models/attribute_type.rb
erp_tech_svcs-3.0.2 app/models/attribute_type.rb
erp_tech_svcs-3.0.1 app/models/attribute_type.rb