Sha256: 94dce6a380d106db093450776f1972758edc50285ee312f838b1d67cca9444c5

Contents?: true

Size: 1.25 KB

Versions: 2

Compression:

Stored size: 1.25 KB

Contents

module Saulabs

  module Reportable

    # A result set as it is returned by the report methods.
    # This is basically a subclass of +Array+ that adds two
    # attributes, +model_class_name+ and +report_name+ that store
    # the name of the model and the report the result set
    # was generated from.
    #
    class ResultSet
      include Enumerable

      # the name of the model the result set is based on
      #
      attr_reader :model_class_name

      # the name of the report the result is based on
      #
      attr_reader :report_name

      # array representation of the result
      #
      def to_a
        @results
      end

      # Initializes a new result set.
      #
      # @param [Array] array
      #   the array that is the actual result
      # @param [String] model_class_name
      #   the name of the model the result set is based on
      # @param [String] report_name
      #   the name of the report the result is based on
      #
      def initialize(array, model_class_name, report_name)
        @results = array
        @model_class_name  = model_class_name
        @report_name = report_name.to_s
      end

      # quack like an Enumerable
      #
      def each(&block)
        @results.each(&block)
      end

    end

  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
reportable-1.4.1 lib/saulabs/reportable/result_set.rb
reportable-1.4.0 lib/saulabs/reportable/result_set.rb