Sha256: 2c8a5cd4ad9637f7012613dd51ff37a2a82e45194a234599c009678319feb9c5
Contents?: true
Size: 1.47 KB
Versions: 5
Compression:
Stored size: 1.47 KB
Contents
require 'fretboards/renderer/svg' module Fretboards class FretboardCollection def initialize(settings = {}) @col = [] @forms = {} @tuning = %w{ g' c' e' a' } @table = "default" end def set_tuning(a) @tuning = a end def add(dots, attrs = {}) fb = fretboard(dots, attrs) @col << fb fb end def define(title, a, attrs = {}) form_add(title, a, { :title => title }.merge(attrs)) end def use(title) raise "#{title} form not available" unless @forms[title] @forms[title] end def fretboard(dots, opts = {}) if opts.is_a? String attrs = {} attrs[:title] = opts else attrs = opts.dup end if dots.is_a? Fretboard fb = dots fb.title = attrs[:title] if attrs[:title] else fb = Fretboard.new(:tuning => @tuning) fb.terse(dots, attrs) end fb end def form_add(name, a, attrs = {}) add(form_create(name, a, attrs)) end def form_create(name, a, attrs = {}) @forms[name] = fretboard(a, attrs) end def renderer(settings = {}) Renderer::Svg.new(settings) end def render_to_files(output_dir = '.', settings = {}) # TODO may we use a filenaming lambda? r = renderer(settings) @col.each do |fb| File.open("#{output_dir}/#{fb.title.gsub(/[^A-z0-9]/, "_")}.svg", "w") { |f| f.puts(r.render(fb)) } end end end end
Version data entries
5 entries across 5 versions & 1 rubygems