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.
# 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
# File lib/text/hyphen/language.rb, line 23 def both @patterns[:both] end
# File lib/text/hyphen/language.rb, line 19 def encoding(enc) @encoding = enc end
# File lib/text/hyphen/language.rb, line 35 def hyphen @patterns[:hyphen] end
# 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
# File lib/text/hyphen/language.rb, line 27 def start @patterns[:start] end
# File lib/text/hyphen/language.rb, line 31 def stop @patterns[:stop] end