Sha256: 0d460e3195f7a5998f1dcf65d9cd01046d7b99b15c8eea73989e3fa1a162a7e7

Contents?: true

Size: 708 Bytes

Versions: 2

Compression:

Stored size: 708 Bytes

Contents

# frozen_string_literal: true

module Pcli
  module Util
    module Cli
      class FieldsFlagsError < StandardError; end

      def self.analyze_fields_flags(all, fields, hash)
        result = {}

        is_negative = nil

        fields.each do |field|
          if all
            result[field] = true
            next
          end

          is_negative = hash[field] if is_negative.nil? && !hash[field].nil?

          if !hash[field].nil? && is_negative != hash[field]
            raise FieldsFlagsError, 'Cannot parsed mixed negative and positive flags!'
          end

          result[field] = hash[field].nil? ? !is_negative : hash[field]
        end

        result
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
pcli-0.1.1 lib/pcli/util/cli.rb
pcli-0.1.0 lib/pcli/util/cli.rb