Class: Pslm::LatexOutputter::PointingFormatter

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

Overview

marks accentuated and preparatory syllables

Constant Summary collapse

MARKS =
{
  :underline => 'underline',
  :bold => 'textbf',
  :semantic => 'accent'
}

Instance Method Summary collapse

Methods inherited from Formatter

format, #psalm_format, #strophe_format, #verse_format, #word_format

Constructor Details

#initialize(options) ⇒ PointingFormatter

Returns a new instance of PointingFormatter.



169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
# File 'lib/pslm/latexoutputter.rb', line 169

def initialize(options)
  super(options)
  @accent_counter = 0
  @preparatories_counter = 0

  # validate options
  if @options.has_key? :tone and
      (@options.has_key? :accents or @options.has_key? :preparatory) then
    raise RuntimeError.new('Overconfigured: both accents/preparatories number and psalm tone specified.')
  elsif @options.has_key? :accents then
    # ok, nothing to do
  elsif @options.has_key? :tone
    # convert psalm tone identifier to numbers
    tone = PsalmPatterns.default.tone_data_str(@options[:tone])
    @options[:accents] = tone.collect {|part| part[0] }
    @options[:preparatory] = tone.collect {|part| part[1] }
  end
end

Instance Method Details

#part_format(text, part, verse, strophe, psalm) ⇒ Object



188
189
190
191
192
193
# File 'lib/pslm/latexoutputter.rb', line 188

def part_format(text, part, verse, strophe, psalm)
  super(text, part, verse, strophe, psalm)
  @accent_counter = 0
  @preparatories_counter = 0
  text
end

#syllable_format(text, syll, word, part, verse, strophe, psalm) ⇒ Object



201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
# File 'lib/pslm/latexoutputter.rb', line 201

def syllable_format(text, syll, word, part, verse, strophe, psalm)
  super(text, syll, word, part, verse, strophe, psalm)
  r = text
  if syll.accent? then
    @accent_counter += 1
    if @accent_counter <= num_accents_for(part) then
      r = "\\#{MARKS[@options[:accent_style]]}{#{r}}"
    end
  end

  if num_preparatory_syllables_for(part) > 0 and
      @accent_counter >= num_accents_for(part) then

    if @accent_counter == num_accents_for(part) and
        @preparatories_counter == 1 then
      r = r + "}"
    end
    if @preparatories_counter == num_preparatory_syllables_for(part) then
      r = '\textit{' + r
    end

    @preparatories_counter += 1
  end

  return r
end