Skip to content

Instantly share code, notes, and snippets.

@tcrayford
Created July 19, 2019 08:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tcrayford/d2cfa70335377c727ddd8c7096a95ce3 to your computer and use it in GitHub Desktop.
Save tcrayford/d2cfa70335377c727ddd8c7096a95ce3 to your computer and use it in GitHub Desktop.
def parse_table(raw)
raw.lines.map do |line|
parts = line.split(':')
key = parts.first.gsub(/^\$/, '')
values = parts.last.split(',').map(&:strip).map {|x| x.split("\t").map(&:strip) }.flatten
if values.count == 1
values = values.first
end
[key, values]
end.to_h
end
def insane_only(ai_table)
ai_table.map do |k,v|
if v.is_a?(Array)
[k, v.first]
else
[k, v]
end
end.to_h
end
def main
first_raw = File.read('./diaspora_2.tbl')
second_raw = File.read('./diaspora.tbl')
first = insane_only(parse_table(first_raw))
second = insane_only(parse_table(second_raw))
longest_key_length = first.keys.map(&:length).max
longest_value_length = first.values.map(&:length).max
first.each do |k,v|
unless v == second[k]
puts "#{k.rjust(longest_key_length, ' ')}\t#{v.rjust(longest_value_length, ' ')}\t#{second[k]}"
end
end
end
main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment