Class: Senrigan::Formatter
- Inherits:
-
Object
- Object
- Senrigan::Formatter
- Defined in:
- lib/senrigan/formatter.rb
Instance Method Summary collapse
- #format(entity) ⇒ Object
- #format_attachment(attachment) ⇒ Object
- #format_header(entity) ⇒ Object
- #format_message(entity) ⇒ Object
- #format_message_change_event(entity) ⇒ Object
- #format_parent(entity) ⇒ Object
- #format_print(entity) ⇒ Object
-
#initialize ⇒ Formatter
constructor
A new instance of Formatter.
Constructor Details
#initialize ⇒ Formatter
Returns a new instance of Formatter.
7 8 |
# File 'lib/senrigan/formatter.rb', line 7 def initialize end |
Instance Method Details
#format(entity) ⇒ Object
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/senrigan/formatter.rb', line 10 def format(entity) case entity when Entities::Message (entity) when Entities::MessageChangeEvent (entity) else entity.inspect end end |
#format_attachment(attachment) ⇒ Object
66 67 68 69 70 71 72 |
# File 'lib/senrigan/formatter.rb', line 66 def () lines = [] lines.push .title.to_s.colorize(:green) unless .title.to_s.empty? lines.push .text.to_s.colorize(:green) unless .text.to_s.empty? lines.push .title_link.to_s.colorize(:green) unless .title_link.to_s.empty? lines.join("\n") end |
#format_header(entity) ⇒ Object
46 47 48 49 50 51 52 53 |
# File 'lib/senrigan/formatter.rb', line 46 def format_header(entity) [ "@#{entity.user.name}#{entity.user.is_bot ? ' [App]' : ''}".to_s.colorize(:light_blue), 'in', "#{entity.channel.is_private ? '🔒 ' : '#'}#{entity.channel.name}".colorize(:light_green), Time.at(entity.ts.to_i).strftime('%H:%M').colorize(:light_black) ].join(' ') end |
#format_message(entity) ⇒ Object
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/senrigan/formatter.rb', line 26 def (entity) lines = [] lines.push format_header(entity) lines.push entity.content unless entity.content.empty? entity..each do || lines.push () end lines.push format_parent(entity.parent) if entity.parent lines.join("\n") end |
#format_message_change_event(entity) ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'lib/senrigan/formatter.rb', line 37 def (entity) if entity..content == entity..content && !entity...empty? && entity...empty? entity...map { |a| (a) }.join("\n") else (entity.) end end |
#format_parent(entity) ⇒ Object
55 56 57 58 59 60 61 62 63 64 |
# File 'lib/senrigan/formatter.rb', line 55 def format_parent(entity) lines = [] lines.push [ '>', "@#{entity.user.name}#{entity.user.is_bot ? ' [App]' : ''}".to_s, Time.at(entity.ts.to_i).strftime('%H:%M') ].join(' ').colorize(:light_black) lines.push "> #{entity.content.split(/\r?\n/).join("\n> ")}".colorize(:light_black) lines.join("\n") end |
#format_print(entity) ⇒ Object
21 22 23 24 |
# File 'lib/senrigan/formatter.rb', line 21 def format_print(entity) str = format(entity) STDOUT.puts str unless str.empty? end |