From fb18352ccc529d3501cca3b0f42919eb408f74c0 Mon Sep 17 00:00:00 2001 From: Matt Moriarity Date: Sat, 4 Aug 2007 18:54:25 -0400 Subject: [PATCH] Added repeated lyrics to the parser --- app/models/song.rb | 2 +- lib/lyric_parser.rb | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/app/models/song.rb b/app/models/song.rb index b7f9255..a36d862 100644 --- a/app/models/song.rb +++ b/app/models/song.rb @@ -1,4 +1,4 @@ -require 'lyric_parser' +require_dependency 'lyric_parser' class Song < ActiveRecord::Base belongs_to :user, :dependent => :destroy diff --git a/lib/lyric_parser.rb b/lib/lyric_parser.rb index 279bb0d..d579585 100644 --- a/lib/lyric_parser.rb +++ b/lib/lyric_parser.rb @@ -28,6 +28,25 @@ module Lyrix parsed[:slides][idx].gsub!("[#{sub}]", parsed[sub]) if parsed[sub] end + + if s =~ /^\[([2-9])x\]/ + parsed[:slides][idx] = (1..($1.to_i)).collect { s.split("\n")[1..-1].join("\n") } + end + end + + parsed[:slides].flatten! + + parsed[:slides].each_with_index do |s,idx| + slide = parsed[:slides][idx].split("\n") + slide.each_with_index do |line,i| + puts line.inspect + if line.strip =~ /\[([2-9])x\]$/ + num = $1.to_i + line = line.gsub("[#{num}x]", "").strip + slide[i] = (1..num).collect { line } + end + end + parsed[:slides][idx] = slide.flatten.join("\n") end parsed -- 2.11.4.GIT