Class: Pslm::LatexOutputter::QuoteFormatter

Inherits:
Formatter
  • Object
show all
Defined in:
lib/pslm/latexoutputter.rb

Overview

replaces dumb quotation marks “” by smarter ones

Constant Summary collapse

STYLES =
{
  :double => ["``", "''"],
  :single => ["'", "'"],
  :guillemets => ['\guillemotright ', '\guillemotleft '],
  :delete => ['', '']
}

Instance Method Summary collapse

Methods inherited from Formatter

format, #part_format, #strophe_format, #syllable_format, #word_format

Constructor Details

#initialize(options) ⇒ QuoteFormatter

Returns a new instance of QuoteFormatter.



410
411
412
413
414
415
416
417
# File 'lib/pslm/latexoutputter.rb', line 410

def initialize(options)
  super(options)
  @style = @options
  unless STYLES.has_key? @style
    raise "Quotation marks style '#{@style}' unknown."
  end
  @quote_counter = 0
end

Instance Method Details

#psalm_format(text, psalm) ⇒ Object



419
420
421
422
423
# File 'lib/pslm/latexoutputter.rb', line 419

def psalm_format(text, psalm)
  super(text, psalm)
  @quote_counter = 0
  text
end

#verse_format(text, verse, strophe, psalm) ⇒ Object



425
426
427
428
429
430
431
432
433
434
# File 'lib/pslm/latexoutputter.rb', line 425

def verse_format(text, verse, strophe, psalm)
  return text.gsub('"') do
    @quote_counter += 1
    if @quote_counter % 2 == 1 then
      STYLES[@style].first
    else
      STYLES[@style].last
    end
  end
end