Class: QDM::Date
- Inherits:
-
Object
- Object
- QDM::Date
- Defined in:
- app/models/qdm/basetypes/date.rb
Overview
Represents a QDM/CQL Date
Instance Attribute Summary collapse
-
#day ⇒ Object
Returns the value of attribute day.
-
#month ⇒ Object
Returns the value of attribute month.
-
#year ⇒ Object
Returns the value of attribute year.
Class Method Summary collapse
-
.demongoize(date_str) ⇒ Object
Get the string as it was stored in the database, and instantiate this custom class from it.
-
.evolve(object) ⇒ Object
Converts the object that was supplied to a criteria and converts it into a database friendly form.
Instance Method Summary collapse
-
#initialize(year = nil, month = nil, day = nil) ⇒ Date
constructor
A new instance of Date.
-
#mongoize ⇒ Object
Converts an object of this instance into a database friendly value.
Constructor Details
#initialize(year = nil, month = nil, day = nil) ⇒ Date
Returns a new instance of Date.
6 7 8 9 10 |
# File 'app/models/qdm/basetypes/date.rb', line 6 def initialize(year = nil, month = nil, day = nil) @year = year @month = month @day = day end |
Instance Attribute Details
#day ⇒ Object
Returns the value of attribute day.
4 5 6 |
# File 'app/models/qdm/basetypes/date.rb', line 4 def day @day end |
#month ⇒ Object
Returns the value of attribute month.
4 5 6 |
# File 'app/models/qdm/basetypes/date.rb', line 4 def month @month end |
#year ⇒ Object
Returns the value of attribute year.
4 5 6 |
# File 'app/models/qdm/basetypes/date.rb', line 4 def year @year end |
Class Method Details
.demongoize(date_str) ⇒ Object
Get the string as it was stored in the database, and instantiate this custom class from it.
20 21 22 23 24 25 26 27 |
# File 'app/models/qdm/basetypes/date.rb', line 20 def demongoize(date_str) return nil unless date_str year = date_str[0..3].to_i month = date_str[5..6].to_i day = date_str[8..10].to_i QDM::Date.new(year, month, day) end |
Instance Method Details
#mongoize ⇒ Object
Converts an object of this instance into a database friendly value.
13 14 15 |
# File 'app/models/qdm/basetypes/date.rb', line 13 def mongoize "#{format('%04d', year)}-#{format('%02d', month)}-#{format('%02d', day)}" end |