class Text::Hyphen::Language

Language scaffolding support for Text::Hyphen. Language hyphenation patterns are defined as instances of this class -- and only this class. This is a deliberate "breaking" of Ruby's concept of duck-typing and is intended to provide an indication that the patterns have been converted from TeX encodings to other encodings (e.g., latin1 or UTF-8) that are more suitable to general text manipulations.

Constants

DASH_RE
DIGIT_RE
EXCEPTION_DASH0_RE
EXCEPTION_DASH1_RE
EXCEPTION_NONUM_RE
NONDIGIT_RE
WORD_END_RE
WORD_START_RE
ZERO_INSERT_RE
ZERO_START_RE

Attributes

exceptions[RW]
isocode[RW]
left[RW]
right[RW]

Public Class Methods

new() { |self| ... } click to toggle source
# File lib/text/hyphen/language.rb, line 106
def initialize
  self.encoding "latin1"
  self.patterns ""
  self.exceptions ""
  self.left = 2
  self.right = 2
  self.isocode = nil

  yield self if block_given?
end

Public Instance Methods

both() click to toggle source
# File lib/text/hyphen/language.rb, line 23
def both
  @patterns[:both]
end
encoding(enc) click to toggle source
# File lib/text/hyphen/language.rb, line 19
def encoding(enc)
  @encoding = enc
end
hyphen() click to toggle source
# File lib/text/hyphen/language.rb, line 35
def hyphen
  @patterns[:hyphen]
end
patterns(pats = nil) click to toggle source
# File lib/text/hyphen/language.rb, line 39
def patterns(pats = nil)
  return @patterns if pats.nil?

  @patterns = {
    :both   => {}, 
    :start  => {},
    :stop   => {},
    :hyphen => {}
  }

  plist = pats.split($/).map { |ln| ln.gsub(%r{%.*$}, '') }
  plist.each do |line|
    line.split.each do |word|
      next if word.empty?

      start = stop = false

      start = true if word.sub!(WORD_START_RE, '')
      stop  = true if word.sub!(WORD_END_RE, '')

      # Insert zeroes and start with some digit
      word.gsub!(ZERO_INSERT_RE) { "#{$1}0" }
      word.gsub!(ZERO_START_RE, "0")

      # This assumes that the pattern lists are already in lowercase
      # form only.
      tag   = word.gsub(DIGIT_RE, '')
      value = word.gsub(NONDIGIT_RE, '')

      if start and stop
        set = :both
      elsif start
        set = :start
      elsif stop
        set = :stop
      else
        set = :hyphen
      end

      @patterns[set][tag] = value
    end
  end

  true
end
start() click to toggle source
# File lib/text/hyphen/language.rb, line 27
def start
  @patterns[:start]
end
stop() click to toggle source
# File lib/text/hyphen/language.rb, line 31
def stop
  @patterns[:stop]
end