class Guard::Karma::Notifier
Constants
- FAILURE_TITLE
- RUNNING_TITLE
- SUCCESS_TITLE
Attributes
options[RW]
Public Class Methods
new(options = {})
click to toggle source
# File lib/guard/karma/notifier.rb, line 10 def initialize(options = {}) @options = options end
Public Instance Methods
notify(summary)
click to toggle source
# File lib/guard/karma/notifier.rb, line 20 def notify(summary) return unless options[:notification] run_count, total_count, failure_count = parse_summary(summary) body = "Executed #{run_count} of #{total_count}" if failure_count > 0 body += " with #{failure_count} failure(s)" end title = title(failure_count) image = image(failure_count) priority = priority(image) Guard::Compat::UI.notify(body, title: title, image: image, priority: priority) end
notify_start()
click to toggle source
# File lib/guard/karma/notifier.rb, line 14 def notify_start return unless options[:notification] Guard::Compat::UI.notify('', title: RUNNING_TITLE, image: :pending, priority: -1) end
Private Instance Methods
image(failure_count)
click to toggle source
# File lib/guard/karma/notifier.rb, line 54 def image(failure_count) if failure_count > 0 :failed else :success end end
parse_summary(summary)
click to toggle source
# File lib/guard/karma/notifier.rb, line 38 def parse_summary(summary) # Example: # Executed x of y (n FAILED) (skipped z) summary.match(/Executed\ (\d+)\ of\ (\d+)\ \((\d+)\ FAILED\)/) do |match| return [match[1].to_i, match[2].to_i, match[3].to_i] end # Example: # Executed x of y (skipped z) SUCCESS summary.match(/Executed\ (\d+)\ of\ (\d+).*\ SUCCESS/) do |match| return [match[1].to_i, match[2].to_i, 0] end [0, 0, 0] end
priority(image)
click to toggle source
# File lib/guard/karma/notifier.rb, line 62 def priority(image) { failed: 2, success: -1 }[image] end
title(failure_count)
click to toggle source
# File lib/guard/karma/notifier.rb, line 66 def title(failure_count) if failure_count > 0 FAILURE_TITLE else SUCCESS_TITLE end end