Class: Crowdskout::Components::Profile

Inherits:
Component
  • Object
show all
Defined in:
lib/crowdskout/components/profiles/profile.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Component

get_value, to_hash_value, #to_json

Instance Attribute Details

#collectionsObject

Returns the value of attribute collections.



10
11
12
# File 'lib/crowdskout/components/profiles/profile.rb', line 10

def collections
  @collections
end

#idObject

Returns the value of attribute id.



10
11
12
# File 'lib/crowdskout/components/profiles/profile.rb', line 10

def id
  @id
end

Class Method Details

.create(props) ⇒ Profile

Factory method to create an Profile object from a json string

Parameters:

  • props (Hash)
    • properties to create object from

Returns:



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/crowdskout/components/profiles/profile.rb', line 15

def self.create(props)
  obj = Profile.new
  obj.collections = []
  if props
    props.each do |key, value|
      if ['id'].include? key.downcase
        obj.send("#{key}=", value) if obj.respond_to? key
      else
        # the key is the name of the collection
        # the value is an array of items
        obj.collections << Components::Collection.create({key => value})
      end
    end
  end
  obj
end

Instance Method Details

#add_genders(gender) ⇒ Array

Add a Gender

Parameters:

  • gender (Gebder)

Returns:

  • (Array)

    the genders array



43
44
45
46
# File 'lib/crowdskout/components/profiles/profile.rb', line 43

def add_genders(gender)
  @genders = [] if @genders.nil?
  @genders << gender
end

#add_names(name) ⇒ Array

Add a Name

Parameters:

  • name (Name)

Returns:

  • (Array)

    the names array



35
36
37
38
# File 'lib/crowdskout/components/profiles/profile.rb', line 35

def add_names(name)
  @names = [] if @names.nil?
  @names << name
end

#to_hashObject

Hash override to generate the correct hash



49
50
51
52
53
54
55
# File 'lib/crowdskout/components/profiles/profile.rb', line 49

def to_hash
  ret_val = { id: id }
  collections.each do |collection|
    ret_val.merge! collection.to_hash
  end
  ret_val
end