Sha256: d296c10c98a2c6e1057232349050fdfee550b5c1065edec32db3aa710434a21a

Contents?: true

Size: 1.05 KB

Versions: 29

Compression:

Stored size: 1.05 KB

Contents

module UniverseCompiler
  module Universe

    module Query

      def basic_criteria
        self.private_methods.grep /^by_/
      end

      def get_entity(type, name)
        res = get_entities criterion: :by_uniq_key, value: [type, name]
        res.empty? ? nil : res.first
      end

      def get_entities(criterion: nil, value: nil, &filter_block)
        res = if criterion.nil? then
                entities.clone
              else
                raise "Invalid criterion '#{criterion}' !" unless basic_criteria.include? criterion
                if value.nil?
                  self.send(criterion).clone
                else
                  self.send(criterion).clone[value]
                end
              end
        res = case res
                when NilClass
                  []
                when Array
                  res
                else
                  [res]
              end
        if block_given?
          res.select! do |entity|
            filter_block.call entity
          end
        end
        res
      end

    end

  end
end

Version data entries

29 entries across 29 versions & 1 rubygems

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