Sha256: 429b96b357194c994d2181181c8e70dfa01cd510be897ecf74e8d4dfd33fe7ec

Contents?: true

Size: 1.12 KB

Versions: 16

Compression:

Stored size: 1.12 KB

Contents

module Ecoportal
  module API
    class V2
      class Page
        class Component
          class GaugeField < Page::Component
            passthrough :value, :max
            passthrough :active_color, read_only: true

            embeds_many :stops, klass: "Ecoportal::API::V2::Page::Component::GaugeStop", order_key: :threshold

            # Adds a stop at `threshold` with `color`
            # @return [Ecoportal::API::V2::Page::Component::GaugeStop]
            def add_stop(threshold: 0.0, color: '#e256d1')
              stop_doc = stops.items_class.new_doc
              stops.upsert!(stop_doc) do |stop|
                stop.threshold = threshold
                stop.color     = color
                yield(stop) if block_given?
              end
            end

            def ordered_stops
              stops.sort_by.with_index do |stop, index|
                [stop.threshold, index]
              end
            end

            def to_s
              value.to_s
            end
          end
        end
      end
    end
  end
end

require 'ecoportal/api/v2/page/component/gauge_stop'

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
ecoportal-api-v2-0.9.3 lib/ecoportal/api/v2/page/component/gauge_field.rb
ecoportal-api-v2-0.9.2 lib/ecoportal/api/v2/page/component/gauge_field.rb
ecoportal-api-v2-0.9.1 lib/ecoportal/api/v2/page/component/gauge_field.rb
ecoportal-api-v2-0.8.33 lib/ecoportal/api/v2/page/component/gauge_field.rb
ecoportal-api-v2-0.8.32 lib/ecoportal/api/v2/page/component/gauge_field.rb
ecoportal-api-v2-0.8.31 lib/ecoportal/api/v2/page/component/gauge_field.rb
ecoportal-api-v2-0.8.30 lib/ecoportal/api/v2/page/component/gauge_field.rb
ecoportal-api-v2-0.8.29 lib/ecoportal/api/v2/page/component/gauge_field.rb
ecoportal-api-v2-0.8.28 lib/ecoportal/api/v2/page/component/gauge_field.rb
ecoportal-api-v2-0.8.27 lib/ecoportal/api/v2/page/component/gauge_field.rb
ecoportal-api-v2-0.8.26 lib/ecoportal/api/v2/page/component/gauge_field.rb
ecoportal-api-v2-0.8.25 lib/ecoportal/api/v2/page/component/gauge_field.rb
ecoportal-api-v2-0.8.24 lib/ecoportal/api/v2/page/component/gauge_field.rb
ecoportal-api-v2-0.8.23 lib/ecoportal/api/v2/page/component/gauge_field.rb
ecoportal-api-v2-0.8.22 lib/ecoportal/api/v2/page/component/gauge_field.rb
ecoportal-api-v2-0.8.21 lib/ecoportal/api/v2/page/component/gauge_field.rb