Class: Komonjo::Model::Message

Inherits:
Object
  • Object
show all
Includes:
Extension::ToJson
Defined in:
lib/komonjo/models/message.rb

Overview

slacke Message

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#channelObject

Returns the value of attribute channel.



6
7
8
# File 'lib/komonjo/models/message.rb', line 6

def channel
  @channel
end

#editedObject

Returns the value of attribute edited.



6
7
8
# File 'lib/komonjo/models/message.rb', line 6

def edited
  @edited
end

#markdownObject (readonly)

for jsonize



8
9
10
# File 'lib/komonjo/models/message.rb', line 8

def markdown
  @markdown
end

#subtypeObject

Returns the value of attribute subtype.



6
7
8
# File 'lib/komonjo/models/message.rb', line 6

def subtype
  @subtype
end

#textObject

Returns the value of attribute text.



6
7
8
# File 'lib/komonjo/models/message.rb', line 6

def text
  @text
end

#tsObject

Returns the value of attribute ts.



6
7
8
# File 'lib/komonjo/models/message.rb', line 6

def ts
  @ts
end

#typeObject

Returns the value of attribute type.



6
7
8
# File 'lib/komonjo/models/message.rb', line 6

def type
  @type
end

#userObject

Returns the value of attribute user.



6
7
8
# File 'lib/komonjo/models/message.rb', line 6

def user
  @user
end

Class Method Details

.create(hash) ⇒ Object



11
12
13
14
15
# File 'lib/komonjo/models/message.rb', line 11

def self.create(hash)
  new.tap do |e|
    hash.each { |k, v| e.instance_variable_set("@#{k}", v) }
  end
end

Instance Method Details

#first_partial_messageObject



30
31
32
# File 'lib/komonjo/models/message.rb', line 30

def first_partial_message
  @first_partial_message ||= PartialMessageFactory.build(text)
end

#icon_markdownObject



42
43
44
# File 'lib/komonjo/models/message.rb', line 42

def icon_markdown
  "* ![#{@user.name} icon](#{@user.profile.image_48})\n"
end

#name_markdownObject



46
47
48
# File 'lib/komonjo/models/message.rb', line 46

def name_markdown
  "\t- #{@user.name}\n"
end

#partial_messagesObject



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/komonjo/models/message.rb', line 17

def partial_messages
  @partial_messages ||=
    begin
      ret = []
      tmp = first_partial_message
      while tmp
        ret << tmp
        tmp = tmp.next
      end
      ret
    end
end

#text_markdownObject



54
55
56
57
# File 'lib/komonjo/models/message.rb', line 54

def text_markdown
  t = partial_messages.map(&:markdown).join
  "\t- #{t}\n"
end

#timestampObject



34
35
36
# File 'lib/komonjo/models/message.rb', line 34

def timestamp
  Time.at(@ts.to_f).strftime('%Y-%m-%d %H:%M:%S')
end

#to_json(*args) ⇒ Object



59
60
61
62
# File 'lib/komonjo/models/message.rb', line 59

def to_json(*args)
  @markdown = to_markdown
  to_json_org(args)
end

#to_json_orgObject



9
# File 'lib/komonjo/models/message.rb', line 9

alias to_json_org to_json

#to_markdownObject



38
39
40
# File 'lib/komonjo/models/message.rb', line 38

def to_markdown
  icon_markdown + name_markdown + ts_markdown + text_markdown
end

#ts_markdownObject



50
51
52
# File 'lib/komonjo/models/message.rb', line 50

def ts_markdown
  "\t- #{timestamp}\n"
end