Class: BeenVerified::User

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

Instance Method Summary collapse

Constructor Details

#initialize(doc) ⇒ User

Returns a new instance of User.



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/beenverified/user.rb', line 4

def initialize(doc)
  @raw_xml = doc.root
  @link_back = doc.root.elements['link_back'].text
  
  #Cycle through all element types and see if there are any of them in the xml response
  @credentials = {}
  BeenVerified::CREDENTIALS.each do |credential_type|
    
    #set array to empty set
    type_array = []
    
    #Get the matching xml node
    credentials = doc.root.elements['credentials'].elements[credential_type[1][:plural]]
    
    #if there are credentials of this type, cycle through and instantiate objects of them
    #and add it to the array
    if credentials
      klass = "BeenVerified::#{credential_type[1][:class]}".constantize
      credentials.elements.each do |credential|
        type_array << klass.new(credential)
      end                    
    end
    eval("@#{credential_type[1][:plural]} = type_array")    
    @credentials[credential_type[1][:plural]] = type_array
    #puts @credentials.size
  end        
  
  def number_of_credentials
    credentials.inject(0){|sum, type| sum = sum+type[1].size }
  end
  
  def identity
    unless  identities.empty?
      identities[0]
    else
      nil
    end
  end
end

Instance Method Details

#identityObject



35
36
37
38
39
40
41
# File 'lib/beenverified/user.rb', line 35

def identity
  unless  identities.empty?
    identities[0]
  else
    nil
  end
end

#number_of_credentialsObject



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

def number_of_credentials
  credentials.inject(0){|sum, type| sum = sum+type[1].size }
end