Class: PrettyChat::Parser
- Inherits:
-
Object
- Object
- PrettyChat::Parser
- Defined in:
- lib/pretty_chat.rb
Instance Attribute Summary collapse
-
#input ⇒ Object
Returns the value of attribute input.
-
#names ⇒ Object
Returns the value of attribute names.
-
#output ⇒ Object
Returns the value of attribute output.
-
#padding ⇒ Object
Returns the value of attribute padding.
Instance Method Summary collapse
-
#initialize(*names) ⇒ Parser
constructor
A new instance of Parser.
- #parse ⇒ Object
Constructor Details
#initialize(*names) ⇒ Parser
Returns a new instance of Parser.
5 6 7 8 9 10 |
# File 'lib/pretty_chat.rb', line 5 def initialize(*names) abort "You must provide a list of names of the chat participants." if names.empty? self.input = `pbpaste` self.names = names self.output = [] end |
Instance Attribute Details
#input ⇒ Object
Returns the value of attribute input.
3 4 5 |
# File 'lib/pretty_chat.rb', line 3 def input @input end |
#names ⇒ Object
Returns the value of attribute names.
3 4 5 |
# File 'lib/pretty_chat.rb', line 3 def names @names end |
#output ⇒ Object
Returns the value of attribute output.
3 4 5 |
# File 'lib/pretty_chat.rb', line 3 def output @output end |
#padding ⇒ Object
Returns the value of attribute padding.
3 4 5 |
# File 'lib/pretty_chat.rb', line 3 def padding @padding end |
Instance Method Details
#parse ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/pretty_chat.rb', line 12 def parse names.each do |name| input.gsub!(/^#{name}\n/, "#{name}: ") input.gsub!(/^\d{1,2}:\d{2}\n/, "") end current_name = "" input.each_line do |line| matches = line.match(/^([\w\s]+): /) if matches current_name = matches[1] else line = "#{current_name}: #{line}" end output << line end output.join end |