Class: Chords::HTMLFormatter

Inherits:
Object
  • Object
show all
Defined in:
lib/chords/html_formatter.rb

Overview

Formats fingerings as <img/> tags (base64-encoded data URIs)

Defined Under Namespace

Classes: NonCache

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(fretboard, cache = NonCache.new) ⇒ HTMLFormatter

Returns a new instance of HTMLFormatter.



14
15
16
17
18
# File 'lib/chords/html_formatter.rb', line 14

def initialize(fretboard, cache=NonCache.new)
  @fretboard = fretboard
  @cache = cache
  @png_formatter = PNGFormatter.new(@fretboard)
end

Instance Attribute Details

#cacheObject

Returns the value of attribute cache.



12
13
14
# File 'lib/chords/html_formatter.rb', line 12

def cache
  @cache
end

Instance Method Details

TODO: accept a separator element in opts



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/chords/html_formatter.rb', line 21

def print(title, fingerings, opts={})
  html = title.empty? ? '' : "<h2>#{title}</h2>\n"
  
  fingerings.each do |fingering|
    html += get_element(fingering, opts)
  end
  
  if opts[:inline]
    html
  else 
    File.open('chords.html', 'w') do |file|
      file.write html
    end
    puts "Wrote chords.html"
  end
end