Sha256: 3669ae34eae6b6018183f00151ba172925a49e10988186e4997c7e021a71c155

Contents?: true

Size: 909 Bytes

Versions: 1

Compression:

Stored size: 909 Bytes

Contents

require_relative 'sheet'
require_relative 'result'

module Intuition
  class Report
    attr_reader :filter
    attr_reader :context

    def initialize(filter, args = {})
      @filter = filter
      @context = args[:context]
      @sheets = []
    end

    def result
      calculate_if_needed
      @result
    end

    def f
      filter
    end

    private

    def calculate
      raise NotImplementedError
    end

    def calculate_if_needed
      calculate unless @calculated
      @calculated = true
      @result = Result.new(@sheets)
    end

    def sheet(name, &block)
      new_sheet = Sheet.new(name)
      yield new_sheet
      add_sheet(new_sheet)
    end

    def add_sheet(sheet)
      @sheets << sheet
    end

    def method_missing(m, *args, &block)
      if context && context.respond_to?(m)
        context.send(m, *args, &block)
      else
        super
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
intuition-0.0.1.alpha1 lib/intuition/report.rb