Sha256: 1b553bcd34b9b40b00f9734e42d8ee11605f2488a3bd0f17378fde48b530f24f

Contents?: true

Size: 924 Bytes

Versions: 1

Compression:

Stored size: 924 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
          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

1 entries across 1 versions & 1 rubygems

Version Path
crowdskout-0.0.8 lib/crowdskout/components/profiles/field.rb