Sha256: 1bc53fe0c02d418389ea1b2c25578a1a67e053a67dd8142589420dededfc0d84

Contents?: true

Size: 976 Bytes

Versions: 1

Compression:

Stored size: 976 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 sort_sheets!
      @sheets.sort_by!{|s| s.title }
    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.alpha2 lib/intuition/report.rb