Sha256: c3b149650a949373f360e7622ed9a5c14a90e1d194751c5ae1f4052784ea1505

Contents?: true

Size: 1.33 KB

Versions: 22

Compression:

Stored size: 1.33 KB

Contents

module Ecoportal
  module API
    class V2
      class Page
        class Component
          class SelectionOption < Common::Content::DoubleModel
            class << self
              def new_doc
                {
                  "id"         => new_uuid,
                  "weight"     => 9999
                }
              end
            end

            passkey     :id
            passforced  :patch_ver, default: 1
            passthrough :name, :value
            passthrough :weight
            passboolean :selected

            def name
              doc["name"] || "#{value}"
            end

            def delete!
              _parent.delete!(self)
            end

            def numeric!
              self.value = block_given?? yield(value) : to_i(value)
            end

            def text!
              self.value = block_given?? yield(value) : value.to_s
            end

            private

            def to_i(value)
              Float(value).to_i
            end

            # https://stackoverflow.com/a/5661695/4352306
            def is_number?(value)
              begin
                true if Float(value)
              rescue ArgumentError => e
                false
              end
            end
          end
        end
      end
    end
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
ecoportal-api-v2-2.0.6 lib/ecoportal/api/v2/page/component/selection_option.rb
ecoportal-api-v2-2.0.5 lib/ecoportal/api/v2/page/component/selection_option.rb
ecoportal-api-v2-2.0.4 lib/ecoportal/api/v2/page/component/selection_option.rb
ecoportal-api-v2-2.0.3 lib/ecoportal/api/v2/page/component/selection_option.rb
ecoportal-api-v2-2.0.2 lib/ecoportal/api/v2/page/component/selection_option.rb
ecoportal-api-v2-2.0.1 lib/ecoportal/api/v2/page/component/selection_option.rb
ecoportal-api-v2-2.0.0 lib/ecoportal/api/v2/page/component/selection_option.rb
ecoportal-api-v2-1.1.8 lib/ecoportal/api/v2/page/component/selection_option.rb
ecoportal-api-v2-1.1.7 lib/ecoportal/api/v2/page/component/selection_option.rb
ecoportal-api-v2-1.1.6 lib/ecoportal/api/v2/page/component/selection_option.rb
ecoportal-api-v2-1.1.5 lib/ecoportal/api/v2/page/component/selection_option.rb
ecoportal-api-v2-1.1.4 lib/ecoportal/api/v2/page/component/selection_option.rb
ecoportal-api-v2-1.1.3 lib/ecoportal/api/v2/page/component/selection_option.rb
ecoportal-api-v2-1.1.2 lib/ecoportal/api/v2/page/component/selection_option.rb
ecoportal-api-v2-1.1.1 lib/ecoportal/api/v2/page/component/selection_option.rb
ecoportal-api-v2-1.0.1 lib/ecoportal/api/v2/page/component/selection_option.rb
ecoportal-api-v2-0.9.7 lib/ecoportal/api/v2/page/component/selection_option.rb
ecoportal-api-v2-0.9.6 lib/ecoportal/api/v2/page/component/selection_option.rb
ecoportal-api-v2-0.9.5 lib/ecoportal/api/v2/page/component/selection_option.rb
ecoportal-api-v2-0.9.4 lib/ecoportal/api/v2/page/component/selection_option.rb