Class: CalendarExtractors::ICalExtractor

Inherits:
CalExtractor show all
Defined in:
lib/extensions/calendar-timekeeping/ical_extractor.rb

Overview

This class handles extraction from iCal sources.

Usage:

  • add the key ical_filepath to you settings file corresponding to the filepath of the ical file you wish to have parsed.

Instance Attribute Summary

Attributes inherited from CalExtractor

#data

Attributes inherited from LEWT::Extension

#command_name, #customers, #enterprise, #lewt_settings, #lewt_stash, #options

Instance Method Summary collapse

Methods inherited from CalExtractor

#isTargetCustomer?, #isTargetDate?

Methods inherited from LEWT::Extension

#get_matched_customers, #lewt_extensions

Constructor Details

#initialize(dateStart, dateEnd, targets, lewt_settings, suppressTargets) ⇒ ICalExtractor

Initialises the object and calls the parent class’ super() method.



18
19
20
21
22
# File 'lib/extensions/calendar-timekeeping/ical_extractor.rb', line 18

def initialize( dateStart, dateEnd, targets, lewt_settings, suppressTargets )
  @calendarPath = lewt_settings["ical_filepath"] || File.expand_path(File.join(File.dirname(__FILE__), "../../../tests/LEWT Schedule.ics"))

  super( dateStart, dateEnd, targets )
end

Instance Method Details

#extractCalendarDataObject

Open iCalender file, parses it, then check events with the regular CalExtractor methods. Sets the data property of this object if match data is found.



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/extensions/calendar-timekeeping/ical_extractor.rb', line 26

def extractCalendarData
  calendars = Icalendar.parse( File.open( @calendarPath ) )
  calendars.each do |calendar|
    calendar.events.each do |e|
      target = self.isTargetCustomer?( e.summary )
      dstart = Time.parse( e.dtstart.to_s )
      dend = Time.parse( e.dtend.to_s )
      if  self.isTargetDate?(dstart) == true &&  target != false
        timeDiff = (dend - dstart) /60/60
        row = LEWT::LEWTLedger.new({
                                     :date_start => dstart, 
                                     :date_end => dend, 
                                     :category => @category, 
                                     :entity => target["name"], 
                                     :description => e.description.to_s,
                                     :quantity => timeDiff, 
                                     :unit_cost => target["rate"]
                                   })

        @data.push( row )
      end
    end
  end
end