class ICU::Name

Public Class Methods

load_alternatives(type, data=nil) click to toggle source

Load a set of first or last name alternatives. If no data is absent, a default set will be loaded. type should be :first or :last.

# File lib/icu_name/name.rb, line 75
def self.load_alternatives(type, data=nil)
  compile_alts(check_type(type), data, true)
end
new(name1='', name2='') click to toggle source

Construct a new name from one or two strings or any objects that have a to_s method.

# File lib/icu_name/name.rb, line 15
def initialize(name1='', name2='')
  @name1 = Util::String.to_utf8(name1.to_s)
  @name2 = Util::String.to_utf8(name2.to_s)
  originalize
  canonicalize
  @first.freeze
  @last.freeze
  @original.freeze
end
reset_alternatives() click to toggle source

Revert to the default sets of alternative names.

# File lib/icu_name/name.rb, line 6
def self.reset_alternatives
  @@alts = Hash.new
  @@cmps = Hash.new
end

Public Instance Methods

alternatives(type) click to toggle source

Show first name or last name alternatives.

# File lib/icu_name/name.rb, line 80
def alternatives(type)
  get_alts(check_type(type))
end
first(opts={}) click to toggle source

First name getter.

# File lib/icu_name/name.rb, line 32
def first(opts={})
  return transliterate(@first, opts[:chars]) if opts[:chars]
  @first.dup
end
last(opts={}) click to toggle source

Last name getter.

# File lib/icu_name/name.rb, line 38
def last(opts={})
  return transliterate(@last, opts[:chars]) if opts[:chars]
  @last.dup
end
match(name1='', name2='', opts={}) click to toggle source

Match another name to this object, returning true or false.

# File lib/icu_name/name.rb, line 67
def match(name1='', name2='', opts={})
  other = Name.new(name1, name2)
  return true if name == other.name
  match_first(first(opts), other.first(opts)) && match_last(last(opts), other.last(opts))
end
name(opts={}) click to toggle source

Return a complete name, first name first, no comma.

# File lib/icu_name/name.rb, line 44
def name(opts={})
  name = ''
  name << first(opts)
  name << ' ' if @first.length > 0 && @last.length > 0
  name << last(opts)
  name
end
original(opts={}) click to toggle source

Original text getter.

# File lib/icu_name/name.rb, line 26
def original(opts={})
  return transliterate(@original, opts[:chars]) if opts[:chars]
  @original.dup
end
rname(opts={}) click to toggle source

Return a reversed complete name, first name last after a comma.

# File lib/icu_name/name.rb, line 53
def rname(opts={})
  name = ''
  name << last(opts)
  name << ', ' if @first.length > 0 && @last.length > 0
  name << first(opts)
  name
end
to_s(opts={}) click to toggle source

Convert to a string (same as rname).

# File lib/icu_name/name.rb, line 62
def to_s(opts={})
  rname(opts)
end