Class: Cadun::User

Inherits:
Object
  • Object
show all
Defined in:
lib/cadun/user.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ User

Returns a new instance of User.



23
24
25
# File 'lib/cadun/user.rb', line 23

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

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method) ⇒ Object



63
64
65
# File 'lib/cadun/user.rb', line 63

def method_missing(method)
  gateway.content[method.to_s]
end

Class Method Details

.find_by_email(email) ⇒ Object



14
15
16
17
# File 'lib/cadun/user.rb', line 14

def self.find_by_email(email)
  email = "#{email}@globomail.com" unless email =~ /^.*@.*$/
  new(:email => email)
end

.find_by_id(cadun_id) ⇒ Object



19
20
21
# File 'lib/cadun/user.rb', line 19

def self.find_by_id(cadun_id)
  new(:cadun_id => cadun_id)
end

Instance Method Details

#addressObject



27
28
29
# File 'lib/cadun/user.rb', line 27

def address
  "#{endereco}, #{numero}"
end

#birthdayObject



31
32
33
# File 'lib/cadun/user.rb', line 31

def birthday
  Date.parse(dataNascimento)
end

#cityObject



47
48
49
# File 'lib/cadun/user.rb', line 47

def city
  cidade['nome'] if cidade.present?
end

#countryObject



43
44
45
# File 'lib/cadun/user.rb', line 43

def country
  pais['nome'] if pais.present?
end

#gatewayObject



67
68
69
# File 'lib/cadun/user.rb', line 67

def gateway
  @gateway ||= Gateway.new(@options)
end

#mobileObject



39
40
41
# File 'lib/cadun/user.rb', line 39

def mobile
  "#{telefoneCelularDdd} #{telefoneCelular}"
end

#phoneObject



35
36
37
# File 'lib/cadun/user.rb', line 35

def phone
  "#{telefoneResidencialDdd} #{telefoneResidencial}"
end

#provision_to_service(service_id) ⇒ Object



59
60
61
# File 'lib/cadun/user.rb', line 59

def provision_to_service(service_id)
  Gateway.provision(id, service_id)
end

#stateObject



51
52
53
# File 'lib/cadun/user.rb', line 51

def state
  estado['sigla'] if estado.present?
end

#to_hashObject



55
56
57
# File 'lib/cadun/user.rb', line 55

def to_hash
  %w(address birthday cadun_id city complement country cpf email gender login mobile name neighborhood phone state status user_type zipcode).inject(Hash.new(0)) { |hash, method| hash[method.to_sym] = (send(method) rescue nil); hash }
end