Sha256: ca8a3890691f7f82d5c6f001e4e21625907d1d07cf300e89431bd6d21aa0b9cc

Contents?: true

Size: 640 Bytes

Versions: 3

Compression:

Stored size: 640 Bytes

Contents

# frozen_string_literal: true

module Remocon
  module ConditionSorter
    CONDITION_KEYS = %i(name expression tagColor).freeze

    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
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
remocon-0.4.1 lib/remocon/sorter/condition_sorter.rb
remocon-0.4.0 lib/remocon/sorter/condition_sorter.rb
remocon-0.4.0.pre.1 lib/remocon/sorter/condition_sorter.rb