Class: Leeno::Model::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/leeno/model/base.rb

Direct Known Subclasses

Canvas, History

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Base

Returns a new instance of Base.



3
4
5
6
7
8
# File 'lib/leeno/model/base.rb', line 3

def initialize data
  self.class::FIELDS.each do |field| 
    value = (field.to_s =~ /_date$/ ? Time.new(data[field.to_s]) : data[field.to_s])
    self.__send__("#{field}=", value)
  end
end

Instance Method Details

#exclude_options!Object



10
11
12
13
# File 'lib/leeno/model/base.rb', line 10

def exclude_options!
  @exclude_options = true
  return self
end

#exclude_options?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/leeno/model/base.rb', line 20

def exclude_options?
  return !!@exclude_options
end

#include_options!Object



15
16
17
18
# File 'lib/leeno/model/base.rb', line 15

def include_options!
  @exclude_options = false
  return self
end

#to_jsonObject



24
25
26
# File 'lib/leeno/model/base.rb', line 24

def to_json
  self.class::FIELDS.inject({}){|hash, field| hash[field] = self.__send__("#{field}");hash }
end