Class: Vimo::Item

Inherits:
ApplicationRecord show all
Defined in:
app/models/vimo/item.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.parse(value_o, kind) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'app/models/vimo/item.rb', line 15

def parse(value_o, kind)
  value = value_o.to_s
  begin
    case kind
    when :string
      value.to_s
    when :integer
      value.to_i
    when :float
      value.to_f
    when :boolean
      value.to_bool unless value_o.nil?
    when :date
      Date.parse(value).to_date.to_s(:db)
    when :datetime
      DateTime.constantize.parse(value).to_datetime.to_s(:db)
    else
      value
    end
  rescue => e
    puts e
    nil
  end
end

Instance Method Details

#as_json(options = nil) ⇒ Object



45
46
47
# File 'app/models/vimo/item.rb', line 45

def as_json(options = nil)
  ({ id: id }).merge(data)
end

#dataObject



41
42
43
# File 'app/models/vimo/item.rb', line 41

def data
  read_attribute(:data) || {}
end