Class: Flamethrower::Campfire::Message
- Inherits:
-
Object
- Object
- Flamethrower::Campfire::Message
- Defined in:
- lib/flamethrower/campfire/message.rb
Constant Summary collapse
- RETRY_SECONDS =
15
Instance Attribute Summary collapse
-
#body ⇒ Object
Returns the value of attribute body.
-
#direction ⇒ Object
Returns the value of attribute direction.
-
#image_converted ⇒ Object
Returns the value of attribute image_converted.
-
#message_type ⇒ Object
Returns the value of attribute message_type.
-
#retry_at ⇒ Object
Returns the value of attribute retry_at.
-
#room ⇒ Object
Returns the value of attribute room.
-
#status ⇒ Object
Returns the value of attribute status.
-
#user ⇒ Object
Returns the value of attribute user.
-
#user_id ⇒ Object
Returns the value of attribute user_id.
Instance Method Summary collapse
- #failed? ⇒ Boolean
- #has_images? ⇒ Boolean
- #image_urls ⇒ Object
- #inbound? ⇒ Boolean
-
#initialize(params = {}) ⇒ Message
constructor
A new instance of Message.
- #mark_delivered! ⇒ Object
- #mark_failed! ⇒ Object
- #mark_pending! ⇒ Object
- #needs_image_conversion? ⇒ Boolean
- #outbound? ⇒ Boolean
- #pending? ⇒ Boolean
- #set_ascii_image(str) ⇒ Object
- #to_irc ⇒ Object
Constructor Details
#initialize(params = {}) ⇒ Message
Returns a new instance of Message.
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/flamethrower/campfire/message.rb', line 8 def initialize(params = {}) @body = params['body'] @user = params['user'] @room = params['room'] @user_id = set_user_id(params) @message_type = params['type'] @direction = params['direction'] @status = "pending" @image_converted = false end |
Instance Attribute Details
#body ⇒ Object
Returns the value of attribute body.
4 5 6 |
# File 'lib/flamethrower/campfire/message.rb', line 4 def body @body end |
#direction ⇒ Object
Returns the value of attribute direction.
4 5 6 |
# File 'lib/flamethrower/campfire/message.rb', line 4 def direction @direction end |
#image_converted ⇒ Object
Returns the value of attribute image_converted.
4 5 6 |
# File 'lib/flamethrower/campfire/message.rb', line 4 def image_converted @image_converted end |
#message_type ⇒ Object
Returns the value of attribute message_type.
4 5 6 |
# File 'lib/flamethrower/campfire/message.rb', line 4 def @message_type end |
#retry_at ⇒ Object
Returns the value of attribute retry_at.
4 5 6 |
# File 'lib/flamethrower/campfire/message.rb', line 4 def retry_at @retry_at end |
#room ⇒ Object
Returns the value of attribute room.
4 5 6 |
# File 'lib/flamethrower/campfire/message.rb', line 4 def room @room end |
#status ⇒ Object
Returns the value of attribute status.
4 5 6 |
# File 'lib/flamethrower/campfire/message.rb', line 4 def status @status end |
#user ⇒ Object
Returns the value of attribute user.
4 5 6 |
# File 'lib/flamethrower/campfire/message.rb', line 4 def user @user end |
#user_id ⇒ Object
Returns the value of attribute user_id.
4 5 6 |
# File 'lib/flamethrower/campfire/message.rb', line 4 def user_id @user_id end |
Instance Method Details
#failed? ⇒ Boolean
32 33 34 |
# File 'lib/flamethrower/campfire/message.rb', line 32 def failed? @status == "failed" end |
#has_images? ⇒ Boolean
60 61 62 |
# File 'lib/flamethrower/campfire/message.rb', line 60 def has_images? image_urls.size > 0 end |
#image_urls ⇒ Object
52 53 54 55 56 57 58 |
# File 'lib/flamethrower/campfire/message.rb', line 52 def image_urls if @body @body.scan(/(https?:\/\/.+?\.(?:jpg|jpeg|gif|png))/i).flatten else [] end end |
#inbound? ⇒ Boolean
44 45 46 |
# File 'lib/flamethrower/campfire/message.rb', line 44 def inbound? @direction == "inbound" end |
#mark_delivered! ⇒ Object
19 20 21 |
# File 'lib/flamethrower/campfire/message.rb', line 19 def mark_delivered! @status = "delivered" end |
#mark_failed! ⇒ Object
23 24 25 26 |
# File 'lib/flamethrower/campfire/message.rb', line 23 def mark_failed! @status = "failed" @retry_at = Time.now + RETRY_SECONDS end |
#mark_pending! ⇒ Object
28 29 30 |
# File 'lib/flamethrower/campfire/message.rb', line 28 def mark_pending! @status = "pending" end |
#needs_image_conversion? ⇒ Boolean
48 49 50 |
# File 'lib/flamethrower/campfire/message.rb', line 48 def needs_image_conversion? has_images? && !@image_converted end |
#outbound? ⇒ Boolean
40 41 42 |
# File 'lib/flamethrower/campfire/message.rb', line 40 def outbound? @direction == "outbound" end |
#pending? ⇒ Boolean
36 37 38 |
# File 'lib/flamethrower/campfire/message.rb', line 36 def pending? @status == "pending" end |
#set_ascii_image(str) ⇒ Object
64 65 66 67 68 |
# File 'lib/flamethrower/campfire/message.rb', line 64 def set_ascii_image(str) @body << "\n#{str}" @message_type = "PasteMessage" @image_converted = true end |
#to_irc ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/flamethrower/campfire/message.rb', line 70 def to_irc case when "TextMessage" irc_string = ":#{@user.to_irc.to_s} PRIVMSG #{@room.to_irc.name} :#{@body}" when "EnterMessage" irc_string = ":#{@user.to_irc.to_s} JOIN #{@room.to_irc.name}" when "KickMessage" irc_string = ":#{@user.to_irc.to_s} PART #{@room.to_irc.name}" when "LeaveMessage" irc_string = ":#{@user.to_irc.to_s} PART #{@room.to_irc.name}" when "PasteMessage" irc_string = else return end Flamethrower::Irc::Message.new(irc_string) end |