Class: YamlNormalizer::Services::Normalize

Inherits:
Base
  • Object
show all
Includes:
Helpers::Normalize, Helpers::ParamParser
Defined in:
lib/yaml_normalizer/services/normalize.rb

Overview

Normalize is a service class that provides functionality to update giving YAML files to a standardized (normalized) format.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helpers::ParamParser

#parse_params, #print_help, #print_version

Methods included from Helpers::Normalize

#normalize_yaml

Methods inherited from Base

call

Constructor Details

#initialize(*args) ⇒ Normalize

Create a Normalize service object by calling .new and passing one or more String that are interpreted as file glob pattern.

Parameters:

  • *args (Array<String>)

    a list of file glob patterns



22
23
24
25
26
27
# File 'lib/yaml_normalizer/services/normalize.rb', line 22

def initialize(*args)
  super
  parse_params(*args)
  files = args.each_with_object([]) { |a, o| o << Dir[a.to_s] }
  @files = files.flatten.sort.uniq
end

Instance Attribute Details

#filesObject (readonly)

files is a sorted array of file path Strings



17
18
19
# File 'lib/yaml_normalizer/services/normalize.rb', line 17

def files
  @files
end

Instance Method Details

#callObject

Normalizes all YAML files defined on instantiation.



30
31
32
# File 'lib/yaml_normalizer/services/normalize.rb', line 30

def call
  files.peach { |file| process(file) }
end