Sha256: 4fc5b7ee6713d21fa0aea1b986bb717c71cfc297a5c3ec56ceab9a0a004389d8

Contents?: true

Size: 1.08 KB

Versions: 15

Compression:

Stored size: 1.08 KB

Contents

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

module Crowdskout
  module Components
    class FieldOptions < Component
      attr_accessor :id, :collection, :options

      # Factory method to create an FieldOptions object from a json string
      # @param [Hash] props - properties to create object from
      # @return [FieldOptions]
      def self.create(props)
        obj = FieldOptions.new
        if props
          props.each do |key, value|
            if key.downcase == 'options'
              if value
                obj.options = []
                value.each do |option|
                  obj.options << Components::Option.create(option)
                end
              end
            else
              obj.send("#{key}=", value) if obj.respond_to? key
            end
          end
        end
        obj
      end

      # Add an Option
      # @param [Option] option
      # @return [Array] the options array
      def add_options(option)
        @options = [] if @options.nil?
        @options << option
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

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