Sha256: 072a19a88ee9686885b2a3f93d5ddd7008622a28b398a15222837f3f7528232a

Contents?: true

Size: 972 Bytes

Versions: 2

Compression:

Stored size: 972 Bytes

Contents

module Esearch
  class Presenter

    # Presenter for elasticsearch result hits
    class Hits < self
      include Enumerable

      # Enumerate contents
      #
      # @return [self]
      #   if block given
      #
      # @return [Enumerator<Hit>]
      #   otherwise
      #
      # @api private
      #
      def each(&block)
        return to_enum unless block_given?

        hits.each do |hit|
          yield Hit.new(hit)
        end
        
        self
      end

      # Return amount of hits in this request
      #
      # @return [Fixnum]
      #
      # @api private
      #
      def size
        hits.size
      end
      
      # Return total amount of hits in the query
      #
      # @return [Fixnum]
      #
      # @api private
      #
      expose_primitive('total')

    private

      # Return raw hits
      #
      # @return [Array]
      #
      # @api private
      #
      expose_primitive(:hits)
      private :hits

    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
esearch-0.2.1 lib/esearch/presenter/hits.rb
esearch-0.2.0 lib/esearch/presenter/hits.rb