Module: RVGP::Base::Grid::HasMultipleSheets::ClassMethods

Defined in:
lib/rvgp/base/grid.rb

Overview

This module contains the Class methods, that are automatically included, at the time RVGP::Base::Grid::HasMultipleSheets is included into a class.

Instance Method Summary collapse

Instance Method Details

#has_sheets(sheet_output_prefix) {|year| ... } ⇒ void

This method returns an undefined value.

Define what additional sheets, this Grid will handle.

Parameters:

  • sheet_output_prefix (String)

    This is used in constructing the output file, and is expected to be a friendly name, describing the container, under which our multiple sheets exist.

Yields:

  • (year)

    Return the sheets, that are available in the given year

Yield Parameters:

  • year (Integer)

    The year being queried.

Yield Returns:

  • (Array<String>)

    The sheets (aka grids) that we can generate for this year



491
492
493
494
# File 'lib/rvgp/base/grid.rb', line 491

def has_sheets(sheet_output_prefix, &block) # rubocop:disable Naming/PredicateName
  @has_sheets = block
  @sheet_output_prefix = sheet_output_prefix
end

#sheet_output_prefixString

Returns the sheet_output_prefix, that was set in #has_sheets

Returns:

  • (String)

    The label for our multiple sheet taxonomy



507
508
509
# File 'lib/rvgp/base/grid.rb', line 507

def sheet_output_prefix
  @sheet_output_prefix
end

#sheets(year) ⇒ Array<String>

Returns the sheets that are available for the given year. This is calculated using the block provided in #has_sheets

Parameters:

  • year (Integer)

    The year being queried.

Returns:

  • (Array<String>)

    What sheets (aka grids) are available this year



500
501
502
503
# File 'lib/rvgp/base/grid.rb', line 500

def sheets(year)
  @sheets ||= {}
  @sheets[year] ||= @has_sheets.call year
end

#uptodate?(year) ⇒ TrueClass, FalseClass

Whether this grid’s outputs are fresh. This is determined, by examing the mtime’s of our #dependency_paths.

Returns:

  • (TrueClass, FalseClass)

    true, if we’re fresh, false if we’re stale.



522
523
524
525
526
# File 'lib/rvgp/base/grid.rb', line 522

def uptodate?(year)
  sheets(year).all? do |sheet|
    FileUtils.uptodate? output_path(year, sheet), dependency_paths
  end
end