Module: Remocon::ConditionSorter

Included in:
InterpreterHelper
Defined in:
lib/remocon/sorter/condition_sorter.rb

Constant Summary collapse

CONDITION_KEYS =
%i(name expression tagColor).freeze

Instance Method Summary collapse

Instance Method Details

#sort_conditions(conditions) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/remocon/sorter/condition_sorter.rb', line 7

def sort_conditions(conditions)
  conditions
    .map(&:symbolize_keys)
    .sort_by { |e| e[:name] }
    .map do |e|
    arr = e.sort do |(a, _), (b, _)|
      if !CONDITION_KEYS.include?(a) && !CONDITION_KEYS.include?(b)
        a <=> b
      else
        (CONDITION_KEYS.index(a) || 10_000) <=> (CONDITION_KEYS.index(b) || 10_000)
      end
    end

    arr.each_with_object({}) { |(k, v), h| h[k] = v }.with_indifferent_access
  end
end