Sha256: 619ee0f91327e6adf1a441ae9440503bd6e7ef601682a2fd3f434c26e88c6832

Contents?: true

Size: 1.34 KB

Versions: 6

Compression:

Stored size: 1.34 KB

Contents

module Ecoportal
  module API
    class V2
      class Page
        class Component
          class SelectionOption < Ecoportal::API::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

6 entries across 6 versions & 1 rubygems

Version Path
ecoportal-api-v2-2.0.12 lib/ecoportal/api/v2/page/component/selection_option.rb
ecoportal-api-v2-2.0.11 lib/ecoportal/api/v2/page/component/selection_option.rb
ecoportal-api-v2-2.0.10 lib/ecoportal/api/v2/page/component/selection_option.rb
ecoportal-api-v2-2.0.9 lib/ecoportal/api/v2/page/component/selection_option.rb
ecoportal-api-v2-2.0.8 lib/ecoportal/api/v2/page/component/selection_option.rb
ecoportal-api-v2-2.0.7 lib/ecoportal/api/v2/page/component/selection_option.rb