Skip to content

Instantly share code, notes, and snippets.

@GusGA
Last active October 16, 2015 16:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GusGA/383d9af923ece7e254d0 to your computer and use it in GitHub Desktop.
Save GusGA/383d9af923ece7e254d0 to your computer and use it in GitHub Desktop.
Script de la canción de Serenata Guayanesa "Con Real y Medio"
class DefaultOrder
def order(data)
data
end
end
class RandomOrder
def order(data)
data.shuffle
end
end
class DefaultFormatter
def format(phrases)
phrases
end
end
class EchoFormatter
def format(phrases)
phrases.zip(phrases).flatten
end
end
class Song
def initialize(orderer: DefaultOrder.new, formatter: DefaultFormatter.new)
@data_song = {}
@animals = orderer.order([:pava, :gata, :chiva, :mona, :lora, :perra, :burra])
@animals.each do |animal|
mother = animal.to_s
son = mother[0..-2] + "ito"
@data_song[animal] = ["compré una #{mother}, y la #{mother} tuvo un #{son}", "Tengo la #{mother}, tengo el #{son}"]
end
@formatter = formatter
end
def recite
line(@animals.count)
end
def line(number)
song = @formatter.format(phrase(number))
"Con real y medio #{song.join(' ')} y siempre tengo mi real y medio "
end
def phrase(number)
@animals.first(number).reverse.map.with_index do |animal, index|
index == 0 ? @data_song[animal].join(' ') : @data_song[animal][1]
end
end
end
@highercomve
Copy link

def phrase(number)
    animals.first(number).reverse.map.with_index do |animal, index|
      if index == 0
        @data_song[animal].join(' ')
      else
        @data_song[animal][1]
      end
    end
end

@GusGA
Copy link
Author

GusGA commented Oct 16, 2015

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment