Module: FanartTv::BaseModel::InstanceMethods

Defined in:
lib/fanart_tv/models/base_model.rb

Instance Method Summary collapse

Instance Method Details

#initialize(params = {}) ⇒ Object



21
22
23
24
25
# File 'lib/fanart_tv/models/base_model.rb', line 21

def initialize(params = {})
  params.each do |field, value|
    self.send :"#{field}=", value
  end
end

#validate_type(val, type) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/fanart_tv/models/base_model.rb', line 27

def validate_type(val, type)
  if type == Integer
    val.to_i
  elsif type == Float
    val.to_f
  elsif type == String
    val.to_s
  elsif type == Time
    if val.nil? or val == ""
      val = "2030-12-31"
    elsif val.split("-").length == 1
      val << "-12-31"
    elsif val.split("-").length == 2
      val << "-31"
    end
    Time.utc(*val.split("-"))
  else
    val
  end
end