From 953e41606ff4c181be19c895a2366b0e052dc593 Mon Sep 17 00:00:00 2001 From: CyberLeo Date: Mon, 11 May 2015 17:46:41 -0500 Subject: [PATCH] Correct list handling --- app.rb | 13 +++++++------ sets/cheesy2.csv | 2 +- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/app.rb b/app.rb index 3e56c34..c57d944 100644 --- a/app.rb +++ b/app.rb @@ -10,17 +10,18 @@ $metafile = "tmp/songtitle" def load_tracklist() file = "sets/#{$set}.csv" csv = CSV.read(File.open(file)) - names = csv.shift + names = csv.shift.map(&:to_sym) $tracklist = csv.map do |row| Hash[*names.zip(row).flatten] end $tracklist.unshift({ - index: 0, - title: '-', - length: 0, - bpm: 0, + index: "0", + title: "-", + length: "0", + bpm: "0", notes: nil }) + $tracklist.sort! {|a,b| a[:index].to_i <=> b[:index].to_i } end load_tracklist @@ -45,7 +46,7 @@ class App < Sinatra::Base return "No such track index." end - title = ( index < 1 ) ? "-" : $tracklist[index - 1]["title"] + title = ( index < 1 ) ? "-" : $tracklist.detect{|a| a[:index].to_i == index.to_i }[:title] File.open($metafile, "a+") do |fp| fp.flock(File::LOCK_EX) diff --git a/sets/cheesy2.csv b/sets/cheesy2.csv index 7cd5455..c75b7a1 100644 --- a/sets/cheesy2.csv +++ b/sets/cheesy2.csv @@ -10,7 +10,7 @@ index,title,length,bpm,notes 9,"DJ Genki - Nyan Cat! ukiukiUKMIX",180.741224,169.9, 10,"Lime - 8bit Dreamer",545.358056,169.7, 11,"Hyperforce vs. IYF - Raise Yr Glass",281.9393,174.8, -12,"Alex Prospect feat. Becci - Ima Turn It Up (Stu Infinity Remix)",356.404422,170.1, +12,"Alex Prospect feat. Becci - Ima Turn It Up (Stu Infinity Remix)",356.404422,170.1,"Short leadin!" 13,"Sugarbabes - About You Now (Breeze & Chris Unknown Remix)",370.259592,170.1, 14,"Redmoon feat. Meron Ryan - Never Let Go (Fracus & Darwin Remix)",316.107755,175.1,"Short leadin!" 15,"S3RL feat. Yuki - Princess Bubblegum",315.454694,175.1, -- 2.42.0