Skip to content

Instantly share code, notes, and snippets.

@BPScott
Created February 7, 2012 23:27

Revisions

  1. BPScott created this gist Feb 7, 2012.
    21 changes: 21 additions & 0 deletions convert.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,21 @@
    #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