Sha256: 107302bea939843bb81b9e41201b49265b830a54434b4271f169998cfeb8e46a

Contents?: true

Size: 890 Bytes

Versions: 10

Compression:

Stored size: 890 Bytes

Contents

module NNEClient
  # A ResultSet holds the results returned by the SOAP API. The ResultSet includes Enumerable
  # so it is possible to use all the regular enumerable methods to iterate over it.
  class ResultSet
    include Enumerable

    def initialize(result)
      @result = result
    end

    # Yield each result in turn
    def each
      company_basic.each do |cb|
        yield Result.new(cb)
      end
    end

    # The to_hash method is used by other parts of the library and can't be
    # made private for now.
    # @!visibility private
    def to_hash
      @result.to_hash
    end

    def total
      window[:total].to_i
    end

    private

    def window
      to_hash[:window]
    end

    def company_basic
      if to_hash[:company_basic].kind_of?(Hash)
        [to_hash[:company_basic]]
      else
        to_hash[:company_basic] || []
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
nne_client-0.0.10 lib/nne_client/result_set.rb
nne_client-0.0.9 lib/nne_client/result_set.rb
nne_client-0.0.8 lib/nne_client/result_set.rb
nne_client-0.0.7 lib/nne_client/result_set.rb
nne_client-0.0.6 lib/nne_client/result_set.rb
nne_client-0.0.5 lib/nne_client/result_set.rb
nne_client-0.0.4 lib/nne_client/result_set.rb
nne_client-0.0.3 lib/nne_client/result_set.rb
nne_client-0.0.2 lib/nne_client/result_set.rb
nne_client-0.0.1 lib/nne_client/result_set.rb