Created
May 24, 2019 07:36
-
-
Save carlosveucv/02a2315b11cb17802eb68b940517eec7 to your computer and use it in GitHub Desktop.
sanitize_compact_hash
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def main | |
files = Dir.entries(".").sort | |
files.each do |file| | |
array = convert_file_to_sanitized_array(file) | |
array_for_file(file, array) unless array.empty? | |
end | |
end | |
def convert_file_to_sanitized_array(file) | |
array = [] | |
File.open(file) do |fp| | |
fp.each do |line| | |
lines = line.split(',') | |
lines.each do |portion| | |
array << sanitize_line(portion.strip) if valid_line?(portion) | |
end | |
end | |
end if File.file?(file) | |
array | |
end | |
def sanitize_line(line) | |
if valid_line?(line) | |
line = line.gsub('{', '').gsub('"', '').gsub('ledger_entry_guid=>', '').gsub('=>', ': ') | |
return line | |
end | |
nil | |
end | |
def valid_line?(line) | |
trace = %w(sidx sord page records ledger_entry_guid date) | |
trace.each do |word| | |
return true if line.include?(word) | |
end | |
false | |
end | |
def array_for_file(file, array_to_write) | |
puts "\n\n#{file}" | |
array_to_write.each do |line| | |
puts line | |
end | |
end | |
main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment