Class: Pslm::LatexOutputter
- Defined in:
- lib/pslm/latexoutputter.rb
Overview
formats a psalm for LaTeX
Defined Under Namespace
Classes: BreakHintsFormatter, FinalAddContentFormatter, Formatter, LettrineFormatter, PartsFormatter, PointingFormatter, QuoteFormatter, SkipVersesFormatter, StrophesFormatter, TitleFormatter, VersesFormatter, WrapperFormatter
Constant Summary collapse
- FORMATTER_ORDER =
each Formatter must have it’s symbol in the order, otherwise it won’t be used
[ :pointing, :break_hints, :parts, :strophes, :verses, :skip_verses, :title, :lettrine, :final_add_content, :wrapper, :prepend_text, :output_append_text, :line_break_last_line, :quote, :mark_short_verses, ]
Constants inherited from Outputter
Instance Method Summary collapse
-
#get_formatter(sym, options) ⇒ Object
takes a Symbol - name of a configuration option, and option/s value; returns an instance of a corresponding Formatter class or nil.
-
#get_formatters(options) ⇒ Object
takes a Hash of options, returns a list of accordingly initialized Formatter instances.
-
#process_psalm(psalm, opts = {}) ⇒ Object
(also: #process)
takes a Psalm, returns a String with the psalm formatted.
- #process_strophe(strophe, opts, psalm, formatters = nil) ⇒ Object
- #process_verse(verse, opts, strophe = nil, psalm = nil, formatters = nil) ⇒ Object
Instance Method Details
#get_formatter(sym, options) ⇒ Object
takes a Symbol - name of a configuration option, and option/s value; returns an instance of a corresponding Formatter class or nil
94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/pslm/latexoutputter.rb', line 94 def get_formatter(sym, ) cls_name = sym.to_s.gsub(/_(\w)/) {|m| m[1].upcase } cls_name[0] = cls_name[0].upcase cls_name += 'Formatter' if self.class.const_defined? cls_name then return self.class.const_get(cls_name).new() else #STDERR.puts "formatter #{cls_name} not found" return nil end end |
#get_formatters(options) ⇒ Object
takes a Hash of options, returns a list of accordingly initialized Formatter instances
83 84 85 86 87 88 89 90 |
# File 'lib/pslm/latexoutputter.rb', line 83 def get_formatters() return FORMATTER_ORDER.collect do |f| next unless .include? f next unless [f] get_formatter(f, [f]) end.compact! end |
#process_psalm(psalm, opts = {}) ⇒ Object Also known as: process
takes a Psalm, returns a String with the psalm formatted
28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/pslm/latexoutputter.rb', line 28 def process_psalm(psalm, opts={}) formatters = get_formatters(opts) # build the output; on each step apply the appropriate method # of each formatter in the given order psalm_assembled = psalm.strophes.collect do |strophe| process_strophe(strophe, opts, psalm, formatters) end.join "\n" return Formatter.format(formatters, :psalm, psalm_assembled, psalm) end |
#process_strophe(strophe, opts, psalm, formatters = nil) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/pslm/latexoutputter.rb', line 44 def process_strophe(strophe, opts, psalm, formatters=nil) formatters = formatters || get_formatters(opts) strophe_assembled = strophe.verses.collect do |verse| process_verse(verse, opts, strophe, psalm, formatters) end.delete_if {|v| v == '' }.join "\n" return Formatter.format(formatters, :strophe, strophe_assembled, strophe, psalm) end |
#process_verse(verse, opts, strophe = nil, psalm = nil, formatters = nil) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/pslm/latexoutputter.rb', line 57 def process_verse(verse, opts, strophe=nil, psalm=nil, formatters=nil) formatters = formatters || get_formatters(opts) verse_assembled = verse.parts.collect do |part| part_assembled = part.words.reverse.collect do |word| word_assembled = word.syllables.reverse.collect do |syll| Formatter.format(formatters, :syllable, syll, syll, word, part, verse, strophe, psalm) end.reverse.join '' Formatter.format(formatters, :word, word_assembled, word, part, verse, strophe, psalm) end.reverse.join ' ' Formatter.format(formatters, :part, part_assembled, part, verse, strophe, psalm) end.join "\n" return Formatter.format(formatters, :verse, verse_assembled, verse, strophe, psalm) end |