class Tracco::TrelloTracker

Public Class Methods

new(custom_config_params = {}) click to toggle source
# File lib/tracco/trello_tracker.rb, line 9
def initialize(custom_config_params = {})
  authorize_on_trello(custom_config_params)
  tracker_username(custom_config_params[:tracker_username])
end

Public Instance Methods

track(starting_date=Date.today) click to toggle source
# File lib/tracco/trello_tracker.rb, line 14
def track(starting_date=Date.today)
  tracking_notifications = tracker.tracking_notifications_since(starting_date)

  oldest, latest = boundary_dates_in(tracking_notifications)
  Trello.logger.info "Processing #{tracking_notifications.size} tracking events (from #{oldest} to #{latest}) starting from #{starting_date}..."

  tracking_notifications.each do |tracking_notification|
    tracking = Tracking::Factory.build_from(tracking_notification)
    begin
      tracked_card = TrackedCard.update_or_create_with(tracking_notification.card)
      tracked_card.add!(tracking)
      log(tracking)

    rescue StandardError => e
      Trello.logger.warn "skipping tracking: #{e.message}".color(:magenta)
      Trello.logger.debug "#{e.backtrace}"
    end
  end
  Trello.logger.info "Done tracking cards!".color(:green)
end

Private Instance Methods

boundary_dates_in(tracking_notifications) click to toggle source
# File lib/tracco/trello_tracker.rb, line 41
def boundary_dates_in(tracking_notifications)
  dates = tracking_notifications.map { |each_tracking_notification| Chronic.parse(each_tracking_notification.date) }
  [dates.min, dates.max]
end
log(tracking) click to toggle source
# File lib/tracco/trello_tracker.rb, line 46
def log(tracking)
  Trello.logger.level > Logger::INFO ? print(".".color(:green)) : puts(tracking.to_s)
end
tracker() click to toggle source
# File lib/tracco/trello_tracker.rb, line 37
def tracker
  @tracker ||= Trello::Member.find(tracker_username)
end