Created
July 19, 2019 08:28
-
-
Save tcrayford/d2cfa70335377c727ddd8c7096a95ce3 to your computer and use it in GitHub Desktop.
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 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