Class: Cache2Html

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

Instance Method Summary collapse

Instance Method Details

#parse_dir(dirname, hash = nil) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/lyrics_ebook/cache2html.rb', line 7

def parse_dir(dirname, hash=nil)
  parser=MiniLyricsParser.new

  @hash=Hash.new{ |hash,key| hash[key]=[] } unless @hash
  @cache=Hash.new{ |hash,key| hash[key]={} } unless @cache
  
  Dir.foreach(dirname) do |filename|
    file=File.join(dirname,filename)
    lp=parser.parse(file)
    if lp
      @hash[lp.artist.upcase.strip] << lp
      @cache[lp.artist][lp.title]= file
    end
  end
end

#to_htmlObject



23
24
25
26
27
28
29
30
# File 'lib/lyrics_ebook/cache2html.rb', line 23

def to_html
  data=@hash.to_a.sort!
  data.each{|r| r[1].sort! }
  template=""
  IO.foreach('template.erb.html') {|line| template << line }
  html=ERB.new(template)
  html.run(binding)
end