Class: FlexBullet::Message

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Message

Returns a new instance of Message.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/flex_bullet/message.rb', line 6

def initialize (args)
  if args[:parsed_json] != nil
    json    = args[:parsed_json]
    @sender = json['sender_name']
    @email  = json['sender_email']
    @iden   = json['sender_iden']
    @body   = json['body']
  else
    @sender = args[:sender] || ''
    @email  = args[:email]
    @iden   = args[:iden] || ''
    @body   = args[:body]
    @title  = args[:title] || ''
  end

  @user_obj = args[:user_obj]
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



4
5
6
# File 'lib/flex_bullet/message.rb', line 4

def body
  @body
end

#emailObject (readonly)

Returns the value of attribute email.



4
5
6
# File 'lib/flex_bullet/message.rb', line 4

def email
  @email
end

#idenObject (readonly)

Returns the value of attribute iden.



4
5
6
# File 'lib/flex_bullet/message.rb', line 4

def iden
  @iden
end

#senderObject (readonly)

Returns the value of attribute sender.



4
5
6
# File 'lib/flex_bullet/message.rb', line 4

def sender
  @sender
end

#titleObject (readonly)

Returns the value of attribute title.



4
5
6
# File 'lib/flex_bullet/message.rb', line 4

def title
  @title
end

#user_objObject (readonly)

Returns the value of attribute user_obj.



4
5
6
# File 'lib/flex_bullet/message.rb', line 4

def user_obj
  @user_obj
end

Instance Method Details

#send_to(*args) ⇒ Object



24
25
26
27
28
29
30
31
32
# File 'lib/flex_bullet/message.rb', line 24

def send_to (*args)
  if args.size == 1
    raise ArgumentError('Message needs assigned user to send self') if user_obj.nil?
    user_obj.client.push_note_to(args.first, title, body)
  elsif args.size == 2
    raise ArgumentError('User must be assigned in first argument') unless args.first.is_a?(FlexBullet::User)
    args.first.client.push_note_to(args[1], title, body)
  end
end

#to_cmdObject



38
39
40
41
# File 'lib/flex_bullet/message.rb', line 38

def to_cmd
  body = @body.split("\n").map(&:strip)
  FlexBullet::Command.new(@sender, @email, body.first, body[1..-1])
end

#user=(user_obj) ⇒ Object



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

def user= (user_obj)
  @user_obj = user_obj
end