Class: Orthotypo::Composer

Inherits:
Object
  • Object
show all
Defined in:
lib/orthotypo/composer.rb

Constant Summary collapse

SPACE =
' '.freeze
NBSP =
' '.freeze
NNBSP =
' '.freeze
NON_BREAKING_SPACE_BEFORE =
[
  ';',
  ':',
  '!',
  '?',
  '”',
  '»',
  '›'
].freeze
NON_BREAKING_SPACE_AFTER =
[
  '“',
  '«',
  '‹'
].freeze

Instance Method Summary collapse

Constructor Details

#initialize(string) ⇒ Composer

Returns a new instance of Composer.



23
24
25
# File 'lib/orthotypo/composer.rb', line 23

def initialize(string)
  @string = string
end

Instance Method Details

#to_sObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/orthotypo/composer.rb', line 27

def to_s
  unless @ortho
    @ortho = @string.dup
    # Espace normal avant -> espace fine insécable avant
    NON_BREAKING_SPACE_BEFORE.each do |char|
      fix(SPACE + char, NNBSP + char)
    end
    # Espace normal après -> espace fine insécable après
    NON_BREAKING_SPACE_AFTER.each do |char|
      fix(char + SPACE, char + NNBSP)
    end
  end
  @ortho
end