class Ecoportal::API::V2::Page::Component::GaugeField

Public Instance Methods

add_stop(threshold: 0.0, color: ' { |stop| ... } click to toggle source

Adds a stop at `threshold` with `color` @return [Ecoportal::API::V2::Page::Component::GaugeStop]

# File lib/ecoportal/api/v2/page/component/gauge_field.rb, line 14
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
ordered_stops() click to toggle source
# File lib/ecoportal/api/v2/page/component/gauge_field.rb, line 23
def ordered_stops
  stops.each_with_index.sort_by do |stop, index|
    (stop.threshold >= 9999) ? [index, index] : [stop.threshold, index]
  end.map(&:first)
end