Class: AttributeValue
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- AttributeValue
- Defined in:
- app/models/attribute_value.rb
Instance Method Summary collapse
- #is_date? ⇒ Boolean
- #remove_unused_types ⇒ Object
- #value_as_data_type ⇒ Object
- #value_as_date ⇒ Object
Instance Method Details
#is_date? ⇒ Boolean
10 11 12 |
# File 'app/models/attribute_value.rb', line 10 def is_date? self.attribute_type.data_type == 'Date' ? true : false end |
#remove_unused_types ⇒ Object
39 40 41 42 43 |
# File 'app/models/attribute_value.rb', line 39 def remove_unused_types AttributeType.includes(:attribute_values).joins('LEFT OUTER JOIN attribute_values on attribute_values.attribute_type_id = attribute_types.id').where('attribute_values.id is null').each do |type| type.destroy end end |
#value_as_data_type ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'app/models/attribute_value.rb', line 14 def value_as_data_type data_type = self.attribute_type.data_type case data_type when "Date" self.value.to_date when "Boolean" self.value == "true" ? true : false when "Int" self.value.to_i when "Float" self.value.to_f else self.value end end |
#value_as_date ⇒ Object
31 32 33 34 35 36 37 |
# File 'app/models/attribute_value.rb', line 31 def value_as_date if self.is_date? self.value.to_date else raise "value is not a Date or is not properly formated" end end |