Class: S3PO::Parser
- Inherits:
-
Object
- Object
- S3PO::Parser
- Defined in:
- lib/s-3po/parser.rb
Class Method Summary collapse
- .commands_from_text(text) ⇒ Object
- .mentions_from_text(text) ⇒ Object
- .parse_event(event) ⇒ Object
- .plain_from_text(text) ⇒ Object
Class Method Details
.commands_from_text(text) ⇒ Object
38 39 40 41 42 |
# File 'lib/s-3po/parser.rb', line 38 def self.commands_from_text(text) commands = [] text.scan(/<!([^>|]*)[^>]*>/) { |m| commands << m[0]} return commands end |
.mentions_from_text(text) ⇒ Object
15 16 17 18 19 |
# File 'lib/s-3po/parser.rb', line 15 def self.mentions_from_text(text) mentions = [] text.scan(/<@([^>|]*)[^>]*>/) { |m| mentions << m[0]} return mentions end |
.parse_event(event) ⇒ Object
8 9 10 11 12 13 |
# File 'lib/s-3po/parser.rb', line 8 def self.parse_event(event) obj = JSON.parse(event, {symbolize_names: true}) return Response.new(obj) if obj[:type].nil? return Message.new(obj) if obj[:type] == 'message' return Event.new(obj) end |
.plain_from_text(text) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/s-3po/parser.rb', line 21 def self.plain_from_text(text) # Copy plain = String.new(text) # remove labels within brackets plain.gsub!(/<([^>|]*)[^>]*>/, '<\1>') # process commands plain.gsub!(/<!(everyone|channel|group)>/, '<@\1>') plain.gsub!(/<!(.*?)>/, '<\1>') # remove brackets plain.gsub!(/<(.*?)>/, '\1') # unescape plain.gsub!('>', '>') plain.gsub!('<', '<') plain.gsub!('&', '&') return plain end |