Class: Defmastership::BatchModifier

Inherits:
Object
  • Object
show all
Defined in:
lib/defmastership/batch_modifier.rb

Overview

Apply modications on a list of related asciidoc sources

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config, adoc_sources) ⇒ BatchModifier

Returns a new instance of BatchModifier.

Parameters:

  • config (YAML)

    the overall modifications configurations

  • adoc_sources (Hash{String => String})

    asciidoctor files to be modified

    • Key: filename

    • Value: file content



24
25
26
27
28
# File 'lib/defmastership/batch_modifier.rb', line 24

def initialize(config, adoc_sources)
  @config = config
  @adoc_sources = adoc_sources
  @changes = []
end

Instance Attribute Details

#adoc_sourcesHash{String => String} (readonly)

Stores the list of asciidoc files to modify and to save

Returns:

  • (Hash{String => String})

    asciidoc sources as modified by modifiers

    • :key filename

    • :value file content



14
15
16
# File 'lib/defmastership/batch_modifier.rb', line 14

def adoc_sources
  @adoc_sources
end

#changesArray<Array<String>> (readonly)

Provides the list of performed modifications (each line: [Modifier, Was, Becomes])

Returns:

  • (Array<Array<String>>)

    List of performed modifications



18
19
20
# File 'lib/defmastership/batch_modifier.rb', line 18

def changes
  @changes
end

#configYAML (readonly)

Stores the overall invocation configuration

Returns:

  • (YAML)

    configuration as eventualy modified by modifiers



9
10
11
# File 'lib/defmastership/batch_modifier.rb', line 9

def config
  @config
end

Instance Method Details

#apply(modifs) ⇒ Object

Apply modications on asciidoc sources of @adoc_sources

Parameters:

  • modifs (Array<String>)

    The modifications to apply



33
34
35
36
37
38
39
40
41
# File 'lib/defmastership/batch_modifier.rb', line 33

def apply(modifs)
  modifs.each do |modif|
    modifier = modifier_from(modif)
    @adoc_sources = modifier.do_modifications(adoc_sources)
    config.fetch(modif)[:config] = modifier.config

    collect_changes(modifier, modif)
  end
end