Class: Mobitex::Status

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Status

Returns a new instance of Status.



27
28
29
# File 'lib/mobitex/status.rb', line 27

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

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



4
5
6
# File 'lib/mobitex/status.rb', line 4

def attributes
  @attributes
end

Class Method Details

.parse(raw_status) ⇒ Object

Public: Parses single raw status from Mobitex response.

Examples

status = Mobitex::Status.parse('Status: 001, Id: 3e2dc963309c6b574f6c7467a62ef25b, Number: 123456789')
status.status # => '001'
status.id     # => '3e2dc963309c6b574f6c7467a62ef25b'
status.number # => '123456789'

Returns Status object.



16
17
18
19
20
21
22
23
24
25
# File 'lib/mobitex/status.rb', line 16

def self.parse(raw_status)
  attributes = {}

  raw_status.to_s.split(',').map do |raw_attribute|
    part = raw_attribute.partition(':')
    attributes[part.first.strip] = part.last.strip
  end

  new(attributes)
end

Instance Method Details

#idObject



35
36
37
# File 'lib/mobitex/status.rb', line 35

def id
  attributes['Id']
end

#numberObject



39
40
41
# File 'lib/mobitex/status.rb', line 39

def number
  attributes['Number']
end

#statusObject



31
32
33
# File 'lib/mobitex/status.rb', line 31

def status
  attributes['Status']
end

#valid?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/mobitex/status.rb', line 43

def valid?
  status == '002'
end