Skip to content

Instantly share code, notes, and snippets.

@blake41
Created July 31, 2015 15:01
Show Gist options
  • Save blake41/8088a4d0743d460724bb to your computer and use it in GitHub Desktop.
Save blake41/8088a4d0743d460724bb to your computer and use it in GitHub Desktop.
def reformat_languages(languages)
result = {}
languages.each_pair do |style, values|
# style like :oo
# values like {
# :javascript => {
# :type => "interpreted"
# }
values.each_pair do |language, attributes|
# language is like :javascript
# attribute is like {
# :type => "interpreted"
# }
# case 1, i've never seen this language before
if result[language].nil?
result[language] = {}
end
attributes.each_pair do |property, property_value|
if property == :type
result[language][:type] = property_value
end
if result[language][:style].nil?
result[language][:style] = []
end
result[language][:style] << style
end
end
end
result
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment