Class: Unitsdb::Commands::Normalize

Inherits:
Base
  • Object
show all
Defined in:
lib/unitsdb/commands/normalize.rb

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from Unitsdb::Commands::Base

Instance Method Details

#run(input = nil, output = nil) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/unitsdb/commands/normalize.rb', line 8

def run(input = nil, output = nil)
  unless @options[:all] || (input && output)
    raise Unitsdb::Errors::InvalidParameterError,
          "INPUT and OUTPUT files are required unless --all flag is specified"
  end

  if @options[:all]
    Unitsdb::Utils::DEFAULT_YAML_FILES.each do |file|
      path = File.join(@options[:database], file)
      next unless File.exist?(path)

      normalize_file(path, path)
      puts "Normalized #{path}"
    end
    puts "All YAML files normalized successfully!"
  end

  return unless input && output

  normalize_file(input, output)
  puts "Normalized YAML written to #{output}"
end