Class: CalendarExtractors::CalExtractor

Inherits:
LEWT::Extension show all
Defined in:
lib/extensions/calendar-timekeeping/extractor.rb

Overview

The CalExtractor class acts as base class for various calender extraction interfaces such as GCalExtractor, ICalExtractor AppleExtractor. It provides some convenience methods that are useful across the various implementations.

Direct Known Subclasses

AppleExtractor, ICalExtractor

Instance Attribute Summary collapse

Attributes inherited from LEWT::Extension

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

Instance Method Summary collapse

Methods inherited from LEWT::Extension

#get_matched_customers, #lewt_extensions

Constructor Details

#initialize(dateStart, dateEnd, targets) ⇒ CalExtractor

Initialises this class. This method should be invoked by sub-classes with super(). It invokes extractCalenderData on the sub-classes behalf when called…

dateStart [String]

a human readable date as a string for the start time period

dateEnd [String]

a human readable date as a string for the end time period

targets [Hash]

a hash containing all the targets returned by the LewtExtension.get_matched_customers() method



20
21
22
23
24
25
26
27
# File 'lib/extensions/calendar-timekeeping/extractor.rb', line 20

def initialize( dateStart, dateEnd, targets )
  @data = LEWT::LEWTBook.new
  @dateStart  = DateTime.parse dateStart.to_s 
  @dateEnd = DateTime.parse dateEnd.to_s
  @targets = targets
  @category = "Hourly Income"
  self.extractCalendarData
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



13
14
15
# File 'lib/extensions/calendar-timekeeping/extractor.rb', line 13

def data
  @data
end

Instance Method Details

#extractCalendarDataObject

Returns the extracted calendar data. Must be implimented by subclasses.



30
31
32
# File 'lib/extensions/calendar-timekeeping/extractor.rb', line 30

def extractCalendarData
  
end

#isTargetCustomer?(evtSearch) ⇒ Boolean

Matches a search string against customer names/aliases

evtSearch [String]

a string to search against such as the title of an event

returns

false when no match found or the target customer details (as a hash) when matched

Returns:

  • (Boolean)


37
38
39
40
41
42
43
44
45
46
# File 'lib/extensions/calendar-timekeeping/extractor.rb', line 37

def isTargetCustomer? ( evtSearch )
  match = false
  @targets.each do |t|
    reg = [ t['alias'], t['name'] ]
    regex = Regexp.new( reg.join("|"), Regexp::IGNORECASE )
    match = regex.match(evtSearch) != nil ? t : false;
    break if match != false
  end
  return match
end

#isTargetDate?(date) ⇒ Boolean

Checks whether an event date is within target range

date [Date]

the date to check against

return

Boolean true/false operation status

Returns:

  • (Boolean)


51
52
53
54
55
56
57
58
# File 'lib/extensions/calendar-timekeeping/extractor.rb', line 51

def isTargetDate? ( date ) 
  d = DateTime.parse(date.to_s)
  check = false
  if d >= @dateStart && d <= @dateEnd
    check = true
  end
  return check
end