Class: AttributeValue

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/attribute_value.rb

Instance Method Summary collapse

Instance Method Details

#is_date?Boolean

Returns:

  • (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_typesObject



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_typeObject



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_dateObject



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