Last active
October 16, 2015 16:28
-
-
Save GusGA/383d9af923ece7e254d0 to your computer and use it in GitHub Desktop.
Script de la canción de Serenata Guayanesa "Con Real y Medio"
This file contains 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
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment