Class: IletiMerkezi::Message

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

Overview

Message

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(phones, text) ⇒ Message

Returns a new instance of Message.



8
9
10
11
# File 'lib/ileti_merkezi/message.rb', line 8

def initialize(phones, text)
  @phones = Array(phones)
  @text   = text.to_s
end

Instance Attribute Details

#phonesObject (readonly)

Returns the value of attribute phones.



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

def phones
  @phones
end

#textObject (readonly)

Returns the value of attribute text.



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

def text
  @text
end

Instance Method Details

#to_hashObject Also known as: to_h



13
14
15
16
17
18
19
20
# File 'lib/ileti_merkezi/message.rb', line 13

def to_hash
  raise InvalidMessageError, inspect unless valid?

  {
    text: text,
    receipents: { number: phones }
  }
end

#valid?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/ileti_merkezi/message.rb', line 24

def valid?
  phones.any? && !text.empty?
end