Class: Ecoportal::API::V2::Page::Component::GaugeField

Inherits:
Ecoportal::API::V2::Page::Component show all
Defined in:
lib/ecoportal/api/v2/page/component/gauge_field.rb

Constant Summary

Constants included from Common::Content::StringDigest

Common::Content::StringDigest::MAX_HASH_LABEL

Constants inherited from Common::Content::DoubleModel

Common::Content::DoubleModel::NOT_USED

Constants included from Common::Content::ClassHelpers

Common::Content::ClassHelpers::NOT_USED

Instance Attribute Summary

Attributes inherited from Common::Content::DoubleModel

#_key, #_parent

Instance Method Summary collapse

Methods inherited from Ecoportal::API::V2::Page::Component

get_class, #indexable_label, new_doc, #ref, #section

Methods included from Common::Content::StringDigest

#hash_label, #indexable_label

Methods inherited from Common::Content::DoubleModel

#_doc_key, #as_json, #as_update, #consolidate!, #dirty?, #doc, embeds_multiple, embeds_one, #initialize, #key, #key=, key?, new_uuid, #original_doc, pass_reader, pass_writer, passarray, passdate, passkey, passthrough, #pretty_print, #replace_doc, #reset!, #root, #to_json

Methods included from Common::Content::ClassHelpers

#instance_variable_name, #new_class, #resolve_class, #to_constant, #to_time, #used_param?

Constructor Details

This class inherits a constructor from Ecoportal::API::Common::Content::DoubleModel

Instance Method Details

#add_stop(threshold: 0.0, color: '#e256d1') ⇒ Ecoportal::API::V2::Page::Component::GaugeStop

Adds a stop at threshold with color



14
15
16
17
18
19
20
21
# File 'lib/ecoportal/api/v2/page/component/gauge_field.rb', line 14

def add_stop (threshold: 0.0, color: '#e256d1')
  stop_doc = Ecoportal::API::V2::Page::Component::GaugeStop.new_doc
  stops.upsert!(stop_doc) do |stop|
    stop.threshold = threshold
    stop.color     = color
    yield(stop) if block_given?
  end
end

#ordered_stopsObject



23
24
25
26
27
# 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