Sha256: defe5217656b2e92b20cc975548c94ecdb55bb1988a1c92f1e9baddb4dc56fb1

Contents?: true

Size: 1.33 KB

Versions: 29

Compression:

Stored size: 1.33 KB

Contents

module UniverseCompiler
  module Utils

    module ArrayUtils


      def contains_only_one_of?(*choices)
        used = used_choices *choices
        return true, used if used.size == 1
        return false, used
      end

      def contains_at_least_one_of?(*choices)
        used = used_choices *choices
        return true, used unless used.empty?
        return false, used
      end

      def contains_all_of?(*choices)
        used = used_choices *choices
        return true, used if used.size == choices.size
        return false, used
      end

      def raises_or_logs(msg, raise_exception=false, logger_level=:error)
        if raise_exception then
          raise UniverseCompiler::Error, msg
        else
          UniverseCompiler.logger.send logger_level, msg
          return false
        end
      end

      private

      def used_choices(*choices)
        choices.map do |choice|
          choice_content = self.send choice
          case choice_content
            when NilClass
              nil
            when Fixnum
              choice
            when String
              choice_content.empty? ? nil : choice
            when Array
              choice_content.empty? ? nil : choice
            when Hash
              choice_content.empty? ? nil : choice
          end
        end .compact
      end



    end

  end
end

Version data entries

29 entries across 29 versions & 1 rubygems

Version Path
universe_compiler-0.5.6 lib/universe_compiler/utils/array_utils.rb
universe_compiler-0.5.5 lib/universe_compiler/utils/array_utils.rb
universe_compiler-0.5.4 lib/universe_compiler/utils/array_utils.rb
universe_compiler-0.5.3 lib/universe_compiler/utils/array_utils.rb
universe_compiler-0.5.2 lib/universe_compiler/utils/array_utils.rb
universe_compiler-0.5.1 lib/universe_compiler/utils/array_utils.rb
universe_compiler-0.4.3 lib/universe_compiler/utils/array_utils.rb
universe_compiler-0.4.2 lib/universe_compiler/utils/array_utils.rb
universe_compiler-0.4.1 lib/universe_compiler/utils/array_utils.rb
universe_compiler-0.4.0 lib/universe_compiler/utils/array_utils.rb
universe_compiler-0.3.12 lib/universe_compiler/utils/array_utils.rb
universe_compiler-0.3.11 lib/universe_compiler/utils/array_utils.rb
universe_compiler-0.3.10 lib/universe_compiler/utils/array_utils.rb
universe_compiler-0.3.9 lib/universe_compiler/utils/array_utils.rb
universe_compiler-0.3.8 lib/universe_compiler/utils/array_utils.rb
universe_compiler-0.3.7 lib/universe_compiler/utils/array_utils.rb
universe_compiler-0.3.6 lib/universe_compiler/utils/array_utils.rb
universe_compiler-0.3.5 lib/universe_compiler/utils/array_utils.rb
universe_compiler-0.3.4 lib/universe_compiler/utils/array_utils.rb
universe_compiler-0.3.3 lib/universe_compiler/utils/array_utils.rb