class Alpha

todo/check: use a module Alphabets with s to keep version and banner separate - why? why not?

Constants

DOWNCASE
add UNACCENT_ES - why? why not?  is Espanyol catalan spelling or spanish (castillian)?

'ñ'=>'ny', ## e.g. Español => Espanyol

MAJOR
MINOR
PATCH
UNACCENT

“simple” unaccent (remove accents/diacritics and unfold ligatures) translation table / mapping

UNACCENT_DE

de,at,ch translation for umlauts

VERSION

Public Class Methods

banner() click to toggle source
count( freq, mapping_or_chars ) click to toggle source
# File lib/alphabets/utils.rb, line 14
def self.count( freq, mapping_or_chars )
  chars = if mapping_or_chars.is_a?( Hash )
            mapping_or_chars.keys
          else   ## todo/fix: check for is_a? Array and if is String split into Array (on char at a time?) - why? why not?
            mapping_or_chars  ## assume it's an array/list of characters
          end

  chars.reduce(0) do |count,ch|
    count += freq[ch]
    count
  end
end
downcase_i18n( name ) click to toggle source
# File lib/alphabets/utils.rb, line 70
def self.downcase_i18n( name )    ## our very own downcase for int'l characters / letters
  sub( name, DOWNCASE )
end
find_unaccenter( key ) click to toggle source
# File lib/alphabets/utils.rb, line 51
def self.find_unaccenter( key )
  if key == :de
    @de ||= Unaccenter.new( UNACCENT_DE )
    @de
  else
    ## use uni(versal) or unicode or something - why? why not?
    ##  use all or int'l (international) - why? why not?
    ##  use en  (english) - why? why not?
    @default ||= Unaccenter.new( UNACCENT )
    @default
  end
end
frequency_table( name ) click to toggle source
# File lib/alphabets/utils.rb, line 4
def self.frequency_table( name )   ## todo/check: use/rename to char_frequency_table
  ## calculate the frequency table of letters, digits, etc.
  freq = Hash.new(0)
  name.each_char do |ch|
     freq[ch] += 1
  end
  freq
end
root() click to toggle source
# File lib/alphabets/version.rb, line 20
def self.root
  File.expand_path( File.dirname(File.dirname(File.dirname(__FILE__))) )
end
sub( name, mapping ) click to toggle source
# File lib/alphabets/utils.rb, line 28
def self.sub( name, mapping )   ## todo/check: use a different/better name - gsub/map/replace/fold/... - why? why not?
  buf = String.new
  name.each_char do |ch|
    buf << if mapping[ch]
              mapping[ch]
            else
              ch
            end
  end
  buf
end
unaccent( name ) click to toggle source
# File lib/alphabets/utils.rb, line 64
def self.unaccent( name )
  @default ||= Unaccenter.new( UNACCENT )
  @default.unaccent( name )
end
version() click to toggle source
# File lib/alphabets/version.rb, line 12
def self.version
  VERSION
end