Class: Leeno::Model::Base
- Inherits:
-
Object
- Object
- Leeno::Model::Base
- Defined in:
- lib/leeno/model/base.rb
Instance Method Summary collapse
- #exclude_options! ⇒ Object
- #exclude_options? ⇒ Boolean
- #include_options! ⇒ Object
-
#initialize(data) ⇒ Base
constructor
A new instance of Base.
- #to_json ⇒ Object
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 = true return self end |
#exclude_options? ⇒ Boolean
20 21 22 |
# File 'lib/leeno/model/base.rb', line 20 def return !!@exclude_options end |
#include_options! ⇒ Object
15 16 17 18 |
# File 'lib/leeno/model/base.rb', line 15 def @exclude_options = false return self end |
#to_json ⇒ Object
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 |