Class: Namie::Formatter
- Inherits:
-
Object
- Object
- Namie::Formatter
- Defined in:
- lib/namie/formatter.rb
Overview
Format name
Constant Summary collapse
- FORMATS =
{ default: '%t %f %m %l %s', airport: '%t %l, %f %m %s', strip: '%f %l' }
- ABBR =
{ t: :title, f: :first, m: :middle, l: :last, s: :suffix }
Instance Attribute Summary collapse
-
#format ⇒ Object
Returns the value of attribute format.
-
#name ⇒ Object
Returns the value of attribute name.
-
#out ⇒ Object
Returns the value of attribute out.
Instance Method Summary collapse
-
#initialize(name, format) ⇒ Formatter
constructor
A new instance of Formatter.
-
#to_s ⇒ Object
%t Title %f First Name %m Middle Name(s) %l Last Name %s suffix.
Constructor Details
#initialize(name, format) ⇒ Formatter
Returns a new instance of Formatter.
19 20 21 22 23 24 |
# File 'lib/namie/formatter.rb', line 19 def initialize(name, format) @name = name format ||= :default @format = format.is_a?(Symbol) ? FORMATS[format] : format @out = @format.dup end |
Instance Attribute Details
#format ⇒ Object
Returns the value of attribute format.
4 5 6 |
# File 'lib/namie/formatter.rb', line 4 def format @format end |
#name ⇒ Object
Returns the value of attribute name.
4 5 6 |
# File 'lib/namie/formatter.rb', line 4 def name @name end |
#out ⇒ Object
Returns the value of attribute out.
4 5 6 |
# File 'lib/namie/formatter.rb', line 4 def out @out end |
Instance Method Details
#to_s ⇒ Object
%t Title %f First Name %m Middle Name(s) %l Last Name %s suffix
33 34 35 36 37 38 39 |
# File 'lib/namie/formatter.rb', line 33 def to_s ABBR.each do |k, v| val = name.send(v) out.gsub!("%#{k}", val || '') end out.gsub(/\s{2,}/, ' ').strip.chomp end |