Class: RemindMe::Utils::ResultPrinter

Inherits:
Object
  • Object
show all
Includes:
Logger
Defined in:
lib/remind_me/utils/result_printer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Logger

#colorize, #green, #log_error, #log_info, #log_with_rails, #rails_being_used?, #red

Constructor Details

#initialize(reminders) ⇒ ResultPrinter

Returns a new instance of ResultPrinter.



10
11
12
# File 'lib/remind_me/utils/result_printer.rb', line 10

def initialize(reminders)
  @reminders = reminders
end

Instance Attribute Details

#remindersObject (readonly)

Returns the value of attribute reminders.



8
9
10
# File 'lib/remind_me/utils/result_printer.rb', line 8

def reminders
  @reminders
end

Instance Method Details



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/remind_me/utils/result_printer.rb', line 14

def print_results
  if reminders.nil? || reminders.empty?
    log_info 'No reminders found'
    exit(0)
  else
    valid_reminders = reminders.reject { |r| r.is_a?(RemindMe::Reminder::InvalidReminder) }
    invalid_reminders = reminders.select { |r| r.is_a?(RemindMe::Reminder::InvalidReminder) }
    if invalid_reminders.size.positive?
      message = invalid_reminders.map(&:message).join("\n")
      log_error(message)
      abort
    else
      valid_condition_met_reminders = valid_reminders.select(&:conditions_met?)
      if valid_condition_met_reminders.size.positive?
        message = valid_condition_met_reminders.map(&:message).join("\n")
        log_error(message)
        abort
      else
        log_info "Found #{reminders.size} REMIND_ME comment(s), but none of the conditions were met..yet!"
      end
    end
  end
end