Sha256: 85ac9443bbd93cb7e99d3d897e5d35398fca72fb586eb38248c78e8a82878aea
Contents?: true
Size: 1.99 KB
Versions: 6
Compression:
Stored size: 1.99 KB
Contents
module Osm class Term attr_reader :id, :section_id, :name, :start, :end # Initialize a new Term using the hash returned by the API call # @param data the hash of data for the object returned by the API 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 # Determine if the term is completly before the passed date # @param date # @returns true if the term is completly before the passed date def before?(date) return @end < date.to_date end # Determine if the term is completly after the passed date # @param date # @returns true if the term is completly after the passed date def after?(date) return @start > date.to_date end # Determine if the term is in the future # @returns true if the term starts after today def future? return @start > Date.today end # Determine if the term is in the past # @returns true if the term finished before today def past? return @end < Date.today end # Determine if the term is current # @returns true if the term started before today and finishes after today def current? return (@start <= Date.today) && (@end >= Date.today) end # Determine if the provided date is within the term # @param date the date to test # @returns true if the term started before the date and finishes after the date def contains_date?(date) return (@start <= date) && (@end >= date) end 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 def ==(another_term) self.id == another_term.try(:id) end end end
Version data entries
6 entries across 6 versions & 1 rubygems
Version | Path |
---|---|
osm-0.0.5 | lib/osm/term.rb |
osm-0.0.4 | lib/osm/term.rb |
osm-0.0.3 | lib/osm/term.rb |
osm-0.0.2 | lib/osm/term.rb |
osm-0.0.1 | lib/osm/term.rb |
osm-0.0.1.alpha | lib/osm/term.rb |