Class: QDM::Date

Inherits:
Object
  • Object
show all
Defined in:
app/models/qdm/basetypes/date.rb

Overview

Represents a QDM/CQL Date

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#dayObject

Returns the value of attribute day.



4
5
6
# File 'app/models/qdm/basetypes/date.rb', line 4

def day
  @day
end

#monthObject

Returns the value of attribute month.



4
5
6
# File 'app/models/qdm/basetypes/date.rb', line 4

def month
  @month
end

#yearObject

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

.evolve(object) ⇒ Object

Converts the object that was supplied to a criteria and converts it into a database friendly form.



31
32
33
34
35
36
# File 'app/models/qdm/basetypes/date.rb', line 31

def evolve(object)
  case object
  when QDM::Date then object.mongoize
  else object
  end
end

Instance Method Details

#mongoizeObject

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