Sha256: bcae116c1ca4d661db7a0471faaf26c37cc251091f4f36eabd790db680504ace

Contents?: true

Size: 1.45 KB

Versions: 14

Compression:

Stored size: 1.45 KB

Contents

#
# profile.rb
# Crowdskout
#
# Copyright (c) 2016 Kyle Schutt. All rights reserved.

module Crowdskout
  module Components
    class Profile < Component
      attr_accessor :id, :collections

      # Factory method to create an Profile object from a json string
      # @param [Hash] props - properties to create object from
      # @return [Profile]
      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

      # Add a Name
      # @param [Name] name
      # @return [Array] the names array
      def add_names(name)
        @names = [] if @names.nil?
        @names << name
      end

      # Add a Gender
      # @param [Gebder] gender
      # @return [Array] the genders array
      def add_genders(gender)
        @genders = [] if @genders.nil?
        @genders << gender
      end

      # Hash override to generate the correct hash
      def to_hash
        ret_val = { id: id }
        collections.each do |collection|
          ret_val.merge! collection.to_hash
        end
        ret_val
      end

    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
crowdskout-0.1.5 lib/crowdskout/components/profiles/profile.rb
crowdskout-0.1.4 lib/crowdskout/components/profiles/profile.rb
crowdskout-0.1.3 lib/crowdskout/components/profiles/profile.rb
crowdskout-0.1.2 lib/crowdskout/components/profiles/profile.rb
crowdskout-0.1.1 lib/crowdskout/components/profiles/profile.rb
crowdskout-0.1.0 lib/crowdskout/components/profiles/profile.rb
crowdskout-0.0.20 lib/crowdskout/components/profiles/profile.rb
crowdskout-0.0.19 lib/crowdskout/components/profiles/profile.rb
crowdskout-0.0.13 lib/crowdskout/components/profiles/profile.rb
crowdskout-0.0.10 lib/crowdskout/components/profiles/profile.rb
crowdskout-0.0.9 lib/crowdskout/components/profiles/profile.rb
crowdskout-0.0.8 lib/crowdskout/components/profiles/profile.rb
crowdskout-0.0.7 lib/crowdskout/components/profiles/profile.rb
crowdskout-0.0.6 lib/crowdskout/components/profiles/profile.rb