class DebrideToOkuribito::Converter

Constants

FILE_NAME
HEADING

Public Class Methods

new(argv) click to toggle source
# File lib/debride2okuribito.rb, line 16
def initialize(argv)
  @argv = argv.clone.freeze
end

Public Instance Methods

convert_yaml() click to toggle source
# File lib/debride2okuribito.rb, line 20
def convert_yaml
  hash = read_debride
  write_yaml(hash)
end
read_debride() click to toggle source
# File lib/debride2okuribito.rb, line 25
def read_debride
  puts "--- Run debride and convert to yaml..."
  debride = Debride.run(@argv.dup)
  debride_to_hash(debride)
end
write_yaml(hash) click to toggle source
# File lib/debride2okuribito.rb, line 31
def write_yaml(hash)
  yaml = YAML.dump(hash)

  # Workaround...
  yaml.gsub!(/^---\n/, "")
  yaml.gsub!(/^- /, "  - ")

  generate_file(yaml, FILE_NAME)
  puts "--- 'okuribito.yml' has been generated."
end

Private Instance Methods

debride_to_hash(debride) click to toggle source
# File lib/debride2okuribito.rb, line 44
def debride_to_hash(debride)
  hash = {}
  debride.missing.each do |klass, methods|
    ary = []
    methods.each do |method|
      if debride.method_locations["#{klass}##{method}"]
        ary << "##{method}"
      elsif debride.method_locations["#{klass}::#{method}"]
        ary << ".#{method}"
      end
    end
    hash.store(klass, ary) unless ary.empty?
  end
  hash
end
generate_file(obj, filename) click to toggle source
# File lib/debride2okuribito.rb, line 60
def generate_file(obj, filename)
  f = File.open(filename, "w")
  f.write(HEADING % @argv.join(" "))
  f.write(obj)
  f.close
end