Class: Chordproko::PlainSong

Inherits:
Object
  • Object
show all
Defined in:
lib/chordproko/plain_song.rb

Instance Method Summary collapse

Constructor Details

#initialize(sheet, options = {transpose: 1}) ⇒ PlainSong

Returns a new instance of PlainSong.



3
4
5
6
# File 'lib/chordproko/plain_song.rb', line 3

def initialize sheet, options={transpose: 1}
	@sheet = sheet
	@options = options
end

Instance Method Details

#chord_group_format(str) ⇒ Object



48
49
50
# File 'lib/chordproko/plain_song.rb', line 48

def chord_group_format str
	str
end

#chord_line_format(str) ⇒ Object



54
55
56
# File 'lib/chordproko/plain_song.rb', line 54

def chord_line_format str
	str
end

#comment_format(str) ⇒ Object



57
58
59
# File 'lib/chordproko/plain_song.rb', line 57

def comment_format str
	str
end

#contentObject



10
11
12
# File 'lib/chordproko/plain_song.rb', line 10

def content
	@content ||= generate
end

#directive_format(str) ⇒ Object



60
61
62
# File 'lib/chordproko/plain_song.rb', line 60

def directive_format str
	str
end

#generateObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/chordproko/plain_song.rb', line 13

def generate
	textified = ""
	@sheet.each do |line|
		chords = ""
		lyrics = ""
		prev_lyrics = ""
		prev_chord = ""
		line.each do |element|
			element.each do |item|
				case item.class.to_s
				when "Chordproko::Comment"
					textified += item.to_s
				when "Chordproko::Directive"
					textified += item.to_s
			  when "Chordproko::ChordGroup"
			  	item.key = @options[:transpose] if @options[:transpose] rescue 0
			  	cgroup = item.to_s
			   	chords += (" " * (prev_lyrics.size - prev_chord.size).abs) + chord_group_format(cgroup)
			   	prev_chord = cgroup

			  when "Chordproko::Lyric"
			    prev_lyrics = item.to_s
			    lyrics += item.to_s
			  end
			end #case
		end #line
	  chord_lyrics = []
	  chord_lyrics << chord_line_format(chords) if chords.size > 0
	  chord_lyrics << lyric_line_format(lyrics) if lyrics.size > 0
		textified += chord_lyrics.join("\n")
		textified += "\n"
	end #sheet
	textified
end

#lyric_format(str) ⇒ Object



63
64
65
# File 'lib/chordproko/plain_song.rb', line 63

def lyric_format str
	str
end

#lyric_line_format(str) ⇒ Object



51
52
53
# File 'lib/chordproko/plain_song.rb', line 51

def lyric_line_format str
	str
end

#to_sObject



7
8
9
# File 'lib/chordproko/plain_song.rb', line 7

def to_s
	content
end