Sha256: 1169e6716e3bb0e93e218f06588c7284bbc80a39bb702e06d0ad3a6330f9c1f4

Contents?: true

Size: 1.1 KB

Versions: 7

Compression:

Stored size: 1.1 KB

Contents

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

            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.each_with_index.sort_by do |stop, index|
                (stop.threshold >= 9999) ? [index, index] : [stop.threshold, index]
              end.map(&:first)
            end

          end
        end
      end
    end
  end
end

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

Version data entries

7 entries across 7 versions & 2 rubygems

Version Path
ecoportal-api-v2-0.8.8 lib/ecoportal/api/v2/page/component/gauge_field.rb
ecoportal-api-v2-0.8.7 lib/ecoportal/api/v2/page/component/gauge_field.rb
ecoportal-api-v2-0.8.6 lib/ecoportal/api/v2/page/component/gauge_field.rb
ecoportal-api-v2-0.8.5 lib/ecoportal/api/v2/page/component/gauge_field.rb
ecoportal-api-v2-0.8.4 lib/ecoportal/api/v2/page/component/gauge_field.rb
ecoportal-api-oozes-0.7.5 lib/ecoportal/api/v2/page/component/gauge_field.rb
ecoportal-api-oozes-0.7.4 lib/ecoportal/api/v2/page/component/gauge_field.rb