Sha256: 2c586edc75d36cecd2f106ff296c6913ea82eaf768aaed9cafda41f0f0bd9b19

Contents?: true

Size: 609 Bytes

Versions: 3

Compression:

Stored size: 609 Bytes

Contents

# frozen_string_literal: true

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

    def sort_conditions(conditions)
      conditions
        .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.3.1 lib/remocon/sorter/condition_sorter.rb
remocon-0.3.0 lib/remocon/sorter/condition_sorter.rb
remocon-0.2.0 lib/remocon/sorter/condition_sorter.rb