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.



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

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

Instance Attribute Details

#cacheObject

Returns the value of attribute cache.



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

def cache
  @cache
end

Instance Method Details

TODO: accept a separator element in opts



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

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