Class: CalendarExtractors::AppleExtractor

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

Overview

This class handles extraction from iCal sources.

Usage:

  • Add the key osxcal_path to your settings file and set its value to the location of your calender directory. This must be the full path.

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) ⇒ AppleExtractor

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



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

def initialize( dateStart, dateEnd, targets, lewt_settings, suppressTargets ) 
  @calendarPath = lewt_settings["osxcal_path"]
  @suppressTargets = suppressTargets
  super( dateStart, dateEnd, targets )
end

Instance Method Details

#aggregateAppleCalendersObject

Scans the apple calender storage directory and compiles a mashup of ical data it finds



27
28
29
30
31
32
33
# File 'lib/extensions/calendar-timekeeping/apple_extractor.rb', line 27

def aggregateAppleCalenders
  calenders = Array.new
  Dir.glob("#{@calendarPath}**/*.ics").each do |path|
    calenders += Icalendar.parse( File.open(path) )
  end
  return calenders
end

#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.



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/extensions/calendar-timekeeping/apple_extractor.rb', line 37

def extractCalendarData
  calendars = aggregateAppleCalenders()
  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 => e.dtstart.to_time, 
                                     :date_end => e.dtend.to_time, 
                                     :category => @category, 
                                     :entity => target["name"], 
                                     :description => e.description.to_s,
                                     :quantity => timeDiff, 
                                     :unit_cost => target["rate"]
                                   })
        @data.push(row)
      end
    end
  end
end