class RUser::Person

This class allows the creation of new users from the RandomUser.me API. @author Joshua Kendall

Constants

KEYS
NIDT

Attributes

cell[R]

@return [String] the user's cell phone number.

city[R]

@return [String] the user's city.

dob[R]

@return [String] the user's birth date.

email[R]

@return [String] the user's email.

first_name[R]

@return [String] the user's first name.

gender[R]

@return [String] the user's gender, either male or female.

last_name[R]

@return [String] the user's last name.

md5[R]

@return [String] the user's md5 hash of the user's salted password.

nationality[R]

@return [String] the user's nationality

nidn[R]

@return [String] the user's national Id number (SSN, PPS, HETU,, etc.).

nidt[R]

@return [String] the user's national Id type (SSN, PPS, HETU, NINO, etc.).

password[R]

@return [String] the user's password.

phone[R]

@return [String] the user's phone number.

postal[R]

@return [String] the user's zip code or postal code.

profile_large_url[R]

@return [String] the user's large profile photo url

profile_medium_url[R]

@return [String] the user's medium profile photo url

profile_thumbnail_url[R]

@return [String] the user's thumbnail profile photo url

registered[R]

@return [String] the user's registration date.

salt[R]

@return [String] the user's password salt.

seed[R]

@return [String] the user's unique seed which allows future calls.

sha1[R]

@return [String] the user's sha1 hash of the user's salted password.

sha256[R]

@return [String] the user's sha256 hash of the user's salted password.

state[R]

@return [String] the user's state.

street[R]

@return [String] the user's street address.

title[R]

@return [String] the user's title (Mr, Mrs, etc.).

username[R]

@return [String] the user's username.

Public Class Methods

new(data, nationality, seed) click to toggle source

Creates a new person object

@param [Hash] data the data used to create the user @return [Person]

# File lib/ruser/person.rb, line 98
def initialize(data, nationality, seed)
  @nationality = nationality
  @seed = seed
  convert(data)
end

Public Instance Methods

convert(data) click to toggle source

Converts a hash to instance variables

@param [Hash] data the data used to create the instance variables

# File lib/ruser/person.rb, line 107
def convert(data)
  data.each do |k, v|
    k = KEYS[k] if KEYS.include?(k)
    v = v.to_s if k.eql? 'zip'

    if NIDT.include?(k)
      instance_variable_set('@nidt', k)
      k = 'nidn'
      v = v.to_s
    end

    var_set(k, v)
  end
end
var_set(k, v) click to toggle source

Sets all instance variables

@param [String] k the key used to create the instance variables @param [String] v the value used to create the instance variables

# File lib/ruser/person.rb, line 126
def var_set(k, v)
  varget = proc { instance_variable_get("@#{k}") }
  varset = proc { |y| instance_variable_set("@#{k}", y) }
  v.is_a?(Hash) ? convert(v) : instance_variable_set("@#{k}", v)
  self.class.send(:define_method, k, varget)
  self.class.send(:define_method, "#{k}=", varset)
end