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