Class: Osm::Term

Inherits:
Object
  • Object
show all
Defined in:
lib/osm/term.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Term

Initialize a new Term using the hash returned by the API call

Parameters:

  • data

    the hash of data for the object returned by the API



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

#endDate (readonly)

Returns when the term ends.

Returns:

  • (Date)

    when the term ends



6
7
8
# File 'lib/osm/term.rb', line 6

def end
  @end
end

#idFixnum (readonly)

Returns the id for the term.

Returns:

  • (Fixnum)

    the id for the term



6
7
8
# File 'lib/osm/term.rb', line 6

def id
  @id
end

#nameFixnum (readonly)

Returns the name of the term.

Returns:

  • (Fixnum)

    the name of the term



6
7
8
# File 'lib/osm/term.rb', line 6

def name
  @name
end

#section_idFixnum (readonly)

Returns the section the term belongs to.

Returns:

  • (Fixnum)

    the section the term belongs to



6
7
8
# File 'lib/osm/term.rb', line 6

def section_id
  @section_id
end

#startDate (readonly)

Returns when the term starts.

Returns:

  • (Date)

    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

Parameters:

  • date (Date)

Returns:

  • (Boolean)

    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

Parameters:

  • date (Date)

Returns:

  • (Boolean)

    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

Parameters:

  • date (Date)

    the date to test

Returns:

  • (Boolean)

    if the term started before the date and finishes after the date



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

Returns:

  • (Boolean)

    if the term started before today and finishes after today



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

Returns:

  • (Boolean)

    if the term starts after today



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

Returns:

  • (Boolean)

    if the term finished before today



49
50
51
# File 'lib/osm/term.rb', line 49

def past?
  return @end < Date.today
end