Class: ICU::Name
- Inherits:
-
Object
- Object
- ICU::Name
- Defined in:
- lib/icu_name/name.rb,
lib/icu_name/version.rb
Constant Summary collapse
- VERSION =
"1.3.0"
Class Method Summary collapse
-
.load_alternatives(type, data = nil) ⇒ Object
Load a set of first or last name alternatives.
-
.reset_alternatives ⇒ Object
Revert to the default sets of alternative names.
Instance Method Summary collapse
-
#alternatives(type) ⇒ Object
Show first name or last name alternatives.
-
#first(opts = {}) ⇒ Object
First name getter.
-
#initialize(name1 = '', name2 = '') ⇒ Name
constructor
Construct a new name from one or two strings or any objects that have a to_s method.
-
#last(opts = {}) ⇒ Object
Last name getter.
-
#match(name1 = '', name2 = '', opts = {}) ⇒ Object
Match another name to this object, returning true or false.
-
#name(opts = {}) ⇒ Object
Return a complete name, first name first, no comma.
-
#original(opts = {}) ⇒ Object
Original text getter.
-
#rname(opts = {}) ⇒ Object
Return a reversed complete name, first name last after a comma.
-
#to_s(opts = {}) ⇒ Object
Convert to a string (same as rname).
Constructor Details
#initialize(name1 = '', name2 = '') ⇒ Name
Construct a new name from one or two strings or any objects that have a to_s method.
15 16 17 18 19 20 21 22 23 |
# 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 |
Class Method Details
.load_alternatives(type, data = nil) ⇒ Object
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
.
75 76 77 |
# File 'lib/icu_name/name.rb', line 75 def self.load_alternatives(type, data=nil) compile_alts(check_type(type), data, true) end |
.reset_alternatives ⇒ Object
Revert to the default sets of alternative names.
6 7 8 9 |
# File 'lib/icu_name/name.rb', line 6 def self.reset_alternatives @@alts = Hash.new @@cmps = Hash.new end |
Instance Method Details
#alternatives(type) ⇒ Object
Show first name or last name alternatives.
80 81 82 |
# File 'lib/icu_name/name.rb', line 80 def alternatives(type) get_alts(check_type(type)) end |
#first(opts = {}) ⇒ Object
First name getter.
32 33 34 35 |
# File 'lib/icu_name/name.rb', line 32 def first(opts={}) return transliterate(@first, opts[:chars]) if opts[:chars] @first.dup end |
#last(opts = {}) ⇒ Object
Last name getter.
38 39 40 41 |
# 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 = {}) ⇒ Object
Match another name to this object, returning true or false.
67 68 69 70 71 |
# 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 = {}) ⇒ Object
Return a complete name, first name first, no comma.
44 45 46 47 48 49 50 |
# 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 = {}) ⇒ Object
Original text getter.
26 27 28 29 |
# File 'lib/icu_name/name.rb', line 26 def original(opts={}) return transliterate(@original, opts[:chars]) if opts[:chars] @original.dup end |
#rname(opts = {}) ⇒ Object
Return a reversed complete name, first name last after a comma.
53 54 55 56 57 58 59 |
# 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 = {}) ⇒ Object
Convert to a string (same as rname).
62 63 64 |
# File 'lib/icu_name/name.rb', line 62 def to_s(opts={}) rname(opts) end |