Class: Fonecal::Event

Inherits:
Object
  • Object
show all
Defined in:
lib/fonecal/event.rb

Direct Known Subclasses

Practice, Qualifying, Race

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(event, timezone) ⇒ Event

Returns a new instance of Event.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/fonecal/event.rb', line 7

def initialize(event, timezone)
  self.name = event[:type]

  # Extract info from date string
  date,month,year = event[:date].split(' ')[1..-1]

  # Convert month from string to integer
  month = Date::MONTHNAMES.index(month)

  # Parse and set starting time
  start_hr, start_m = event[:start].split(':')

  # Set timezone to what was given
  Time.zone = timezone.zone

  # Look up timezone in day, taking dst into account
  @start = Time.zone.local(year, month, date, start_hr, start_m, 0)

  # Parse and set ending time
  if event[:end] # a practice sessions
    end_hr, end_m = event[:end].split(':')
    @end = Time.zone.local(year, month, date, end_hr, end_m, 0)
  elsif self.class == Qualifying
    @end = @start + (1.hour + 30.minutes)
  else # race
    @end = @start + 4.hours
  end
end

Instance Attribute Details

#endObject

Returns the value of attribute end.



5
6
7
# File 'lib/fonecal/event.rb', line 5

def end
  @end
end

#nameObject

Returns the value of attribute name.



5
6
7
# File 'lib/fonecal/event.rb', line 5

def name
  @name
end

#startObject

Returns the value of attribute start.



5
6
7
# File 'lib/fonecal/event.rb', line 5

def start
  @start
end