Class: SmsBackupRenderer::Participant

Inherits:
Object
  • Object
show all
Defined in:
lib/sms_backup_renderer/models.rb

Overview

Represents a single sender or recipient of an SMS or MMS message.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Participant

Returns a new instance of Participant.



16
17
18
19
20
21
# File 'lib/sms_backup_renderer/models.rb', line 16

def initialize(args)
  @address = args[:address]
  @name = args[:name]
  @owner = args[:owner]
  @sender = args[:sender]
end

Instance Attribute Details

#addressObject (readonly)

Returns the String address of the participant, such as ‘1 (234) 567-890’.



5
6
7
# File 'lib/sms_backup_renderer/models.rb', line 5

def address
  @address
end

#nameObject (readonly)

Returns the String contact name for the participant, or nil if unknown.



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

def name
  @name
end

#ownerObject (readonly)

Returns true if this participant is the owner of the archive, otherwise false.



11
12
13
# File 'lib/sms_backup_renderer/models.rb', line 11

def owner
  @owner
end

#senderObject (readonly)

Returns true if this participant is a sender of the message, false if they are a recipient.



14
15
16
# File 'lib/sms_backup_renderer/models.rb', line 14

def sender
  @sender
end

Class Method Details

.normalize_address(address) ⇒ Object

Normalizes a given address, for example ‘1 (234) 567-890’ to ‘1234567890’.

TODO: This is currently done in a very hacky, incomplete, embarrassingly-US-centric way.

address - String address to normalize

Returns the String normalized address.



34
35
36
37
# File 'lib/sms_backup_renderer/models.rb', line 34

def self.normalize_address(address)
  address.gsub(/[\s\(\)\+\-]/, '')
      .gsub(/\A1(\d{10})\z/, '\\1')
end

Instance Method Details

#normalized_addressObject



23
24
25
# File 'lib/sms_backup_renderer/models.rb', line 23

def normalized_address
  @normalized_address ||= Participant.normalize_address(address)
end