class Pipl::FieldsContainer
Constants
- CLASS_CONTAINER
Attributes
addresses[R]
dob[R]
educations[R]
emails[R]
ethnicities[R]
gender[R]
images[R]
jobs[R]
languages[R]
names[R]
origin_countries[R]
phones[R]
relationships[R]
urls[R]
user_ids[R]
usernames[R]
Public Class Methods
fields_from_hash(h)
click to toggle source
# File lib/pipl/containers.rb, line 56 def self.fields_from_hash(h) fields = self::CLASS_CONTAINER.map do |cls_name, container| cls = Pipl.const_get cls_name h[container.to_sym].map { |x| cls.from_hash(x) } if h.key? container.to_sym end .flatten.compact fields << DOB.from_hash(h[:dob]) if h.key? :dob fields << Gender.from_hash(h[:gender]) if h.key? :gender fields end
from_hash(h)
click to toggle source
# File lib/pipl/containers.rb, line 52 def self.from_hash(h) raise AbstractMethodInvoked.new end
new(params={})
click to toggle source
# File lib/pipl/containers.rb, line 30 def initialize(params={}) @names = [] @addresses = [] @phones = [] @emails = [] @jobs = [] @educations = [] @images = [] @usernames = [] @user_ids = [] @urls = [] @ethnicities = [] @languages = [] @origin_countries = [] @relationships = [] @tags = [] @dob = nil @gender = nil add_fields params[:fields] if params.key? :fields end
Public Instance Methods
add_field(field)
click to toggle source
# File lib/pipl/containers.rb, line 82 def add_field(field) cls_sym = field.class.name.split('::').last.to_sym container = self.class::CLASS_CONTAINER[cls_sym] if container instance_variable_get("@#{container}") << field elsif cls_sym == :DOB @dob = field elsif cls_sym == :Gender @gender = field else raise ArgumentError.new("Object of type #{field.class} is an invalid field") end end
add_fields(fields)
click to toggle source
# File lib/pipl/containers.rb, line 78 def add_fields(fields) fields.each { |f| add_field f } end
address()
click to toggle source
# File lib/pipl/containers.rb, line 108 def address @addresses.first unless @addresses.empty? end
all_fields()
click to toggle source
# File lib/pipl/containers.rb, line 96 def all_fields fields = self.class::CLASS_CONTAINER.values.map { |container| instance_variable_get("@#{container}") } .flatten.compact fields << @dob if @dob fields << @gender if @gender fields end
education()
click to toggle source
# File lib/pipl/containers.rb, line 112 def education @educations.first unless @educations.empty? end
email()
click to toggle source
# File lib/pipl/containers.rb, line 132 def email @emails.first unless @emails.empty? end
ethnicity()
click to toggle source
# File lib/pipl/containers.rb, line 120 def ethnicity @ethnicities.first unless @ethnicities.empty? end
fields_to_hash()
click to toggle source
# File lib/pipl/containers.rb, line 67 def fields_to_hash h = {} h[:dob] = @dob.to_hash if @dob h[:gender] = @gender.to_hash if @gender self.class::CLASS_CONTAINER.values.each do |container| fields = instance_variable_get("@#{container}") h[container.to_sym] = fields.map { |field| field.to_hash }.compact unless fields.empty? end h.reject { |_, value| value.nil? or (value.kind_of?(Array) and value.empty?) } end
image()
click to toggle source
# File lib/pipl/containers.rb, line 140 def image @images.first unless @images.empty? end
job()
click to toggle source
# File lib/pipl/containers.rb, line 104 def job @jobs.first unless @jobs.empty? end
language()
click to toggle source
# File lib/pipl/containers.rb, line 116 def language @languages.first unless @languages.empty? end
name()
click to toggle source
# File lib/pipl/containers.rb, line 136 def name @names.first unless @names.empty? end
origin_country()
click to toggle source
# File lib/pipl/containers.rb, line 124 def origin_country @origin_countries.first unless @origin_countries.empty? end
phone()
click to toggle source
# File lib/pipl/containers.rb, line 128 def phone @phones.first unless @phones.empty? end
relationship()
click to toggle source
# File lib/pipl/containers.rb, line 156 def relationship @relationships.first unless @relationships.empty? end
url()
click to toggle source
# File lib/pipl/containers.rb, line 144 def url @urls.first unless @urls.empty? end
user_id()
click to toggle source
# File lib/pipl/containers.rb, line 152 def user_id @user_ids.first unless @user_ids.empty? end
username()
click to toggle source
# File lib/pipl/containers.rb, line 148 def username @usernames.first unless @usernames.empty? end