module Ecoportal module API class V2 class Page class Component class GaugeStop < Common::Content::DoubleModel class << self def new_doc { "id" => new_uuid, "threshold" => nil, "color" => nil } end end passkey :id passforced :patch_ver, default: 1 passthrough :threshold, :color # Assign the color to the stop. # @note These are the available colors: # - :blue, :blue_greyed, :blue_light # - :turquoise, :jade, :green, :pistachio, :avocado # - :yellow, :orange, :pumpkin, :red, :magenta, :fuchsia, :purple, :violet # @param value [String, Symbol] you can use a `symbol` to specify a color def color=(value) value = to_color(value) if value.is_a?(Symbol) doc["color"] = value end # @return [Symbol] to get the `color` sym code def color_sym color_maps.each do |k, v| return k if color == v end :undefined end private def to_color(value) return nil unless valid_color?(value) return value if value.is_a?(String) color_maps[value] end def valid_color?(value) return true if value.is_a?(String) && colors.any? {|c| c == value} return true if value.is_a?(Symbol) && color_syms.any? {|s| s == value} end def color_syms @color_syms ||= color_maps.keys end def colors @colors ||= color_maps.values end def color_maps @color_maps ||= [ [:blue, "#5656e2"], [:blue_greyed, "#568be2"], [:blue_light, "#56c0e2"], [:turquoise, "#56e2cf"], [:jade, "#56e29b"], [:green, "#56e267"], [:pistachio, "#79e256"], [:avocado, "#aee256"], [:yellow, "#e2e156"], [:orange, "#e2ad56"], [:pumpkin, "#e27956"], [:red, "#e25667"], [:magenta, "#e2569c"], [:fuchsia, "#e256d1"], [:purple, "#be56e2"], [:violet, "#8a56e2"] ].to_h end end end end end end end