Class: Osm::Term
- Inherits:
-
Object
- Object
- Osm::Term
- Defined in:
- lib/osm/term.rb
Instance Attribute Summary collapse
-
#end ⇒ Date
readonly
When the term ends.
-
#id ⇒ Fixnum
readonly
The id for the term.
-
#name ⇒ Fixnum
readonly
The name of the term.
-
#section_id ⇒ Fixnum
readonly
The section the term belongs to.
-
#start ⇒ Date
readonly
When the term starts.
Instance Method Summary collapse
- #<=>(another_term) ⇒ Object
- #==(another_term) ⇒ Object
-
#after?(date) ⇒ Boolean
Determine if the term is completly after the passed date.
-
#before?(date) ⇒ Boolean
Determine if the term is completly before the passed date.
-
#contains_date?(date) ⇒ Boolean
Determine if the provided date is within the term.
-
#current? ⇒ Boolean
Determine if the term is current.
-
#future? ⇒ Boolean
Determine if the term is in the future.
-
#initialize(data) ⇒ Term
constructor
Initialize a new Term using the hash returned by the API call.
-
#past? ⇒ Boolean
Determine if the term is in the past.
Constructor Details
#initialize(data) ⇒ Term
Initialize a new Term using the hash returned by the API call
19 20 21 22 23 24 25 |
# File 'lib/osm/term.rb', line 19 def initialize(data) @id = Osm::to_i_or_nil(data['termid']) @section_id = Osm::to_i_or_nil(data['sectionid']) @name = data['name'] @start = Osm::parse_date(data['startdate']) @end = Osm::parse_date(data['enddate']) end |
Instance Attribute Details
#end ⇒ Date (readonly)
Returns when the term ends.
6 7 8 |
# File 'lib/osm/term.rb', line 6 def end @end end |
#id ⇒ Fixnum (readonly)
Returns the id for the term.
6 7 8 |
# File 'lib/osm/term.rb', line 6 def id @id end |
#name ⇒ Fixnum (readonly)
Returns the name of the term.
6 7 8 |
# File 'lib/osm/term.rb', line 6 def name @name end |
#section_id ⇒ Fixnum (readonly)
Returns the section the term belongs to.
6 7 8 |
# File 'lib/osm/term.rb', line 6 def section_id @section_id end |
#start ⇒ Date (readonly)
Returns when the term starts.
6 7 8 |
# File 'lib/osm/term.rb', line 6 def start @start end |
Instance Method Details
#<=>(another_term) ⇒ Object
66 67 68 69 70 71 72 73 74 |
# File 'lib/osm/term.rb', line 66 def <=>(another_term) compare = self.section_id <=> another_term.try(:section_id) return compare unless compare == 0 compare = self.start <=> another_term.try(:start) return compare unless compare == 0 self.id <=> another_term.try(:id) end |
#==(another_term) ⇒ Object
76 77 78 |
# File 'lib/osm/term.rb', line 76 def ==(another_term) self.id == another_term.try(:id) end |
#after?(date) ⇒ Boolean
Determine if the term is completly after the passed date
37 38 39 |
# File 'lib/osm/term.rb', line 37 def after?(date) return @start > date.to_date end |
#before?(date) ⇒ Boolean
Determine if the term is completly before the passed date
30 31 32 |
# File 'lib/osm/term.rb', line 30 def before?(date) return @end < date.to_date end |
#contains_date?(date) ⇒ Boolean
Determine if the provided date is within the term
62 63 64 |
# File 'lib/osm/term.rb', line 62 def contains_date?(date) return (@start <= date) && (@end >= date) end |
#current? ⇒ Boolean
Determine if the term is current
55 56 57 |
# File 'lib/osm/term.rb', line 55 def current? return (@start <= Date.today) && (@end >= Date.today) end |
#future? ⇒ Boolean
Determine if the term is in the future
43 44 45 |
# File 'lib/osm/term.rb', line 43 def future? return @start > Date.today end |
#past? ⇒ Boolean
Determine if the term is in the past
49 50 51 |
# File 'lib/osm/term.rb', line 49 def past? return @end < Date.today end |