Created
February 7, 2012 23:27
-
-
Save BPScott/1762954 to your computer and use it in GitHub Desktop.
Fuckingawesomesongs.com songs object => one file per song
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
#Place in the root of your fuckingawesomesongs.com folder | |
#I convert the current contents of songs.rb into a one file per song structure | |
require 'YAML' | |
require_relative 'lib/songs' | |
def slugify string | |
string.downcase.gsub(/&/, 'and').gsub(/\s+/, '-').gsub(/[^a-z0-9-]/, '') | |
end | |
Songs.all.each do |song| | |
artist = song[:artist] | |
track = song[:track] | |
url = song[:url] | |
yaml_filename = "songs/#{slugify(artist)}-#{slugify(track)}.yml" | |
yaml_content = "artist: #{artist}\ntrack: #{track}\nurl: #{url}" | |
File.open yaml_filename, 'w' do |f| | |
f.write yaml_content | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment