Class: Vagalume::LyricFormatter

Inherits:
Object
  • Object
show all
Defined in:
lib/vagalume/lyric_formatter.rb

Class Method Summary collapse

Class Method Details

.format(search, options) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/vagalume/lyric_formatter.rb', line 3

def format(search, options)
  status = search.status
  song = search.song
  translated_song = search.translations.with_language(Vagalume::Language::PORTUGUESE)
  output = "\n\n"

  return "No lyric found" if status == Vagalume::Status::NOT_FOUND || status == Vagalume::Status::SONG_NOT_FOUND
  return "\n\n#{song.name}\n\n#{song.lyric}" unless options[:translation]
  return "No translation found" if translated_song.nil?

  bigger_line = bigger_line(song.lyric)
  lyric_array = [song.name, ""]
  translation_array = [translated_song.name, ""]

  lyric_array += song.lyric.split("\n")
  translation_array += translated_song.lyric.split("\n")

  lyric_array.each_with_index do |lyric_line, index|
    output += lyric_line + separator(bigger_line, lyric_line) + translation_array[index].to_s + "\n"
  end
  output
end