Class: BulkReplace::ReplacementSet

Inherits:
Object
  • Object
show all
Defined in:
lib/bulk_replace/replacement_set.rb

Class Method Summary collapse

Class Method Details

.from_config(path) ⇒ Object



8
9
10
11
12
13
14
15
16
# File 'lib/bulk_replace/replacement_set.rb', line 8

def self.from_config(path)
  raw = YAML.safe_load(File.read(path), symbolize_names: true)
  unless raw.is_a?(Hash) && raw[:replacements].is_a?(Array)
    raise ArgumentError,
          "Config must contain a 'replacements' key"
  end

  raw[:replacements].map { |r| Replacement.new(**r) }
end

.from_inline(from:, to:) ⇒ Object



18
19
20
# File 'lib/bulk_replace/replacement_set.rb', line 18

def self.from_inline(from:, to:)
  [Replacement.new(from: from, to: to)]
end