Class: Lyrics2Html

Inherits:
Object
  • Object
show all
Defined in:
lib/lyrics_ebook/lyrics2html.rb

Instance Method Summary collapse

Instance Method Details

#add_lyrics(lyrics) ⇒ Object



12
13
14
15
16
17
18
19
# File 'lib/lyrics_ebook/lyrics2html.rb', line 12

def add_lyrics(lyrics)
  @hash=Hash.new{ |hash,key| hash[key]=[] } unless @hash
  lyrics.each do |lyric|
    unless lyric.text.nil?
      @hash[lyric.artist.upcase.strip] << lyric
    end
  end
end

#to_epub(name) ⇒ Object



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
47
48
49
50
# File 'lib/lyrics_ebook/lyrics2html.rb', line 21

def to_epub name
  ext=File.extname(name)
  basename=File.basename(name,ext)
  @html_files=[]
  Dir.mktmpdir do |base_dir|
    build_pages base_dir
    nav1=build_nav
    files=[]
    @html_files.each do |file|
      files << {file=>'pages'}
    end
    epub = EeePub.make do
      title       basename
      creator     'lyrics-ebook'
      publisher   'maner'
      date        Date.today.to_s
      identifier  'http://example.com/book/foo', :scheme => 'URL'
      uid         'http://example.com/book/foo'
      files files
      nav nav1
      guide  [
        {:type => 'toc', :title => 'Table of Contents', :href => 'pages/artists.xhtml'},
        {:type => 'cover', :title => 'Cover', :href => 'pages/cover.xhtml'}
      ]
    end
    name=name+".epub" if ext==""
    epub.save(name)
    puts "Created "+name
  end
end