Class: Eve::Messenger
- Inherits:
-
Object
- Object
- Eve::Messenger
- Defined in:
- lib/eve/messenger.rb
Instance Attribute Summary collapse
-
#display ⇒ Object
Returns the value of attribute display.
-
#history(flag = nil) ⇒ Object
Returns the value of attribute history.
-
#nok_filters ⇒ Object
Returns the value of attribute nok_filters.
-
#ok_filters ⇒ Object
Returns the value of attribute ok_filters.
-
#piggy_backs ⇒ Object
Returns the value of attribute piggy_backs.
Instance Method Summary collapse
- #add_filter(raw_input) ⇒ Object
- #event_machine ⇒ Object
- #event_machine? ⇒ Boolean
- #file? ⇒ Boolean
- #has_flag?(flag) ⇒ Boolean
-
#initialize(data = {}) ⇒ Messenger
constructor
A new instance of Messenger.
- #is_data_only? ⇒ Boolean
- #overwrite_file? ⇒ Boolean
- #print(output, options = {}) ⇒ Object
- #reset ⇒ Object
- #was_printed?(msg) ⇒ Boolean
Constructor Details
#initialize(data = {}) ⇒ Messenger
Returns a new instance of Messenger.
7 8 9 10 11 12 13 |
# File 'lib/eve/messenger.rb', line 7 def initialize(data = {}) @display = data[:display] || :stdio @piggy_backs = [] @ok_filters = [] @nok_filters = [] reset end |
Instance Attribute Details
#display ⇒ Object
Returns the value of attribute display.
5 6 7 |
# File 'lib/eve/messenger.rb', line 5 def display @display end |
#history(flag = nil) ⇒ Object
Returns the value of attribute history.
5 6 7 |
# File 'lib/eve/messenger.rb', line 5 def history @history end |
#nok_filters ⇒ Object
Returns the value of attribute nok_filters.
5 6 7 |
# File 'lib/eve/messenger.rb', line 5 def nok_filters @nok_filters end |
#ok_filters ⇒ Object
Returns the value of attribute ok_filters.
5 6 7 |
# File 'lib/eve/messenger.rb', line 5 def ok_filters @ok_filters end |
#piggy_backs ⇒ Object
Returns the value of attribute piggy_backs.
5 6 7 |
# File 'lib/eve/messenger.rb', line 5 def piggy_backs @piggy_backs end |
Instance Method Details
#add_filter(raw_input) ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/eve/messenger.rb', line 15 def add_filter(raw_input) raw_input = "#{raw_input}" if raw_input.start_with?("!") @nok_filters << raw_input[1..-1] else @ok_filters << raw_input end end |
#event_machine ⇒ Object
32 33 34 |
# File 'lib/eve/messenger.rb', line 32 def event_machine @display[:event_machine] end |
#event_machine? ⇒ Boolean
28 29 30 |
# File 'lib/eve/messenger.rb', line 28 def event_machine? @display.kind_of?(Hash) && !@display[:event_machine].nil? end |
#file? ⇒ Boolean
36 37 38 |
# File 'lib/eve/messenger.rb', line 36 def file? @display.kind_of?(Hash) && !@display[:filename].nil? end |
#has_flag?(flag) ⇒ Boolean
59 60 61 |
# File 'lib/eve/messenger.rb', line 59 def has_flag?(flag) return !@flagged_history[flag].nil? end |
#is_data_only? ⇒ Boolean
44 45 46 |
# File 'lib/eve/messenger.rb', line 44 def is_data_only? @display.kind_of?(Hash) && @display[:mode] == "data_only" end |
#overwrite_file? ⇒ Boolean
40 41 42 |
# File 'lib/eve/messenger.rb', line 40 def overwrite_file? file? && @display[:mode] == :overwrite end |
#print(output, options = {}) ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/eve/messenger.rb', line 90 def print(output, = {}) @piggy_backs.each { |m| m.print(output,.clone) } return unless should_print?() add_history(output,.delete(:flag)) if @display == :stdio && .empty? STDOUT.print output elsif @display == :stdio Kernel.ap output, elsif event_machine? event_machine.send_data(output) elsif file? system("mkdir -p #{Pathname.new(@display[:filename]).parent}") open(@display[:filename], overwrite_file? ? "w" : "a+") { |f| f.puts(output) } else output end end |
#reset ⇒ Object
48 49 50 51 52 |
# File 'lib/eve/messenger.rb', line 48 def reset @flagged_history = {} @history = [] @piggy_backs.each { |m| m.reset } end |
#was_printed?(msg) ⇒ Boolean
63 64 65 |
# File 'lib/eve/messenger.rb', line 63 def was_printed?(msg) @history.include?(msg) end |