Sha256: 6375eea5ce5ae8f20c2d254fd70bb9bf5855058574dd388e7e61aa4ae0fce348

Contents?: true

Size: 929 Bytes

Versions: 2

Compression:

Stored size: 929 Bytes

Contents

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

module Crowdskout
  module Components
    class Field < Component
      # value can either be a string or a hash
      attr_accessor :key_name, :value

      # Factory method to create an Field object from a json string
      # @param [String] key_name - name of the Field
      # @param [Hash or String] value - properties to create object from
      # @return [Field]
      def self.create(props)
        obj = Field.new
        props.each do |key, value|
          obj.key_name = key
          if value.is_a?(Hash)
            obj.value = Value.create(value)
          else
            obj.value = value.to_s
          end
        end
        obj
      end

      # Hash override to generate the correct hash
      def to_hash
        {
          key_name => (value.is_a?(String) ? value : value.to_hash)
        }
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
crowdskout-0.0.7 lib/crowdskout/components/profiles/field.rb
crowdskout-0.0.6 lib/crowdskout/components/profiles/field.rb