module Tracco::Tracking::Base

Constants

DATE_REGEXP
DURATION_REGEXP
TIME_CONVERTERS

Public Class Methods

new(tracking_notification) click to toggle source
# File lib/tracco/tracking/base.rb, line 21
def initialize(tracking_notification)
  @tracking_notification = tracking_notification
end

Public Instance Methods

date() click to toggle source
# File lib/tracco/tracking/base.rb, line 25
def date
  Chronic.parse(date_as_string).to_date
end
to_s() click to toggle source
# File lib/tracco/tracking/base.rb, line 29
def to_s
  "[#{date}] From #{notifier.username.color(:green)}\t on card '#{trello_card.name.color(:yellow)}': #{tracking_message}"
end

Private Instance Methods

convert_to_hours(duration_as_string) click to toggle source
# File lib/tracco/tracking/base.rb, line 59
def convert_to_hours(duration_as_string)
  return if duration_as_string.nil?

  time_scale = duration_as_string.slice!(-1)
  converter = TIME_CONVERTERS[time_scale]
  converter.call(Float(duration_as_string))
end
date_as_string() click to toggle source
# File lib/tracco/tracking/base.rb, line 67
def date_as_string
  case raw_tracking
  when DATE_REGEXP
    day, month, year = raw_tracking.scan(DATE_REGEXP).flatten
    "#{year}-#{month}-#{day}"
  when /yesterday\s+\+#{DURATION_REGEXP}/, /\+#{DURATION_REGEXP}\s+yesterday/
      (notification_date - 1).to_s
  else
    tracking_notification.date
  end
end
extract_match_from_raw_tracking(regexp) click to toggle source
# File lib/tracco/tracking/base.rb, line 79
def extract_match_from_raw_tracking(regexp)
  extracted = nil
  raw_tracking.scan(regexp) do |match|
    extracted = match.first
  end

  extracted
end
notification_date() click to toggle source
# File lib/tracco/tracking/base.rb, line 43
def notification_date
  Chronic.parse(tracking_notification.date).to_date
end
raw_tracking() click to toggle source
# File lib/tracco/tracking/base.rb, line 47
def raw_tracking
  @raw_tracking ||= remove_tracker_from(tracking_message)
end
remove_tracker_from(tracking_message) click to toggle source
# File lib/tracco/tracking/base.rb, line 51
def remove_tracker_from(tracking_message)
  tracking_message.sub(/^\s*@\w+\s/, "")
end
tracking_message() click to toggle source
# File lib/tracco/tracking/base.rb, line 55
def tracking_message
  tracking_notification.data['text']
end
tracking_notification() click to toggle source
# File lib/tracco/tracking/base.rb, line 35
def tracking_notification
  @tracking_notification
end
trello_card() click to toggle source
# File lib/tracco/tracking/base.rb, line 39
def trello_card
  @trello_card ||= tracking_notification.card
end