Class: Sheetah::TemplateConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/sheetah/template_config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(types: Types::Container.new) ⇒ TemplateConfig

Returns a new instance of TemplateConfig.



7
8
9
# File 'lib/sheetah/template_config.rb', line 7

def initialize(types: Types::Container.new)
  @types = types
end

Instance Attribute Details

#typesObject (readonly)

Returns the value of attribute types.



11
12
13
# File 'lib/sheetah/template_config.rb', line 11

def types
  @types
end

Instance Method Details

#header(key, index) ⇒ Array(String, #match?)

Given an attribute key and a possibily-nil column index, return the header and header pattern for that column.

The return value should be an array with two items:

  1. The first item is the header, as a String.

  2. The second item is the header pattern, and should respond to ‘#match?` with a boolean

    value. Instances of Regexp will obviously do, but the requirement is really about the
    `#match?` method.
    

Parameters:

  • key (Symbol, String)
  • index (Integer, nil)

Returns:

  • (Array(String, #match?))


26
27
28
29
30
31
32
33
# File 'lib/sheetah/template_config.rb', line 26

def header(key, index)
  header = key.to_s.capitalize
  header = "#{header} #{index + 1}" if index

  pattern = /^#{Regexp.escape(header)}$/i

  [header, pattern]
end