Class: Flowpi::Message

Inherits:
Object
  • Object
show all
Defined in:
lib/flowpi.rb

Constant Summary collapse

MESSAGE_TYPES =
%w(message comment)

Instance Method Summary collapse

Constructor Details

#initialize(data = {}) ⇒ Message

Returns a new instance of Message.



58
59
60
# File 'lib/flowpi.rb', line 58

def initialize(data = {})
  @data = data
end

Instance Method Details

#contentObject



71
72
73
74
75
76
77
78
# File 'lib/flowpi.rb', line 71

def content
  if @data['content'].kind_of?(Hash)
    content = @data['content']['text']
  else
    content = @data['content']
  end
  content.gsub(/[^a-z ]/i, '')
end

#has_content?Boolean

Returns:

  • (Boolean)


62
63
64
# File 'lib/flowpi.rb', line 62

def has_content?
  MESSAGE_TYPES.include?(@data['event'])
end

#parse(line) ⇒ Object



66
67
68
69
# File 'lib/flowpi.rb', line 66

def parse(line)
  @data = JSON.parse(line)
  self
end