Class: Mongoid::Name
- Inherits:
-
String
- Object
- String
- Mongoid::Name
- Defined in:
- lib/mongoid-name.rb
Instance Attribute Summary collapse
-
#first ⇒ Object
readonly
Returns the value of attribute first.
-
#last ⇒ Object
readonly
Returns the value of attribute last.
-
#middle ⇒ Object
readonly
Returns the value of attribute middle.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(*args) ⇒ Name
constructor
Name.new(‘AJ’, ‘Ostrow’) Name.new(‘Alexander’, ‘Jacob’, ‘Ostrow’) Name.new(%w(AJ Ostrow)) Name.new(%w(Alexander Jacob Ostrow)).
- #to_a ⇒ Object (also: #mongoize)
- #to_h ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(*args) ⇒ Name
Name.new(‘AJ’, ‘Ostrow’) Name.new(‘Alexander’, ‘Jacob’, ‘Ostrow’) Name.new(%w(AJ Ostrow)) Name.new(%w(Alexander Jacob Ostrow))
9 10 11 12 13 14 |
# File 'lib/mongoid-name.rb', line 9 def initialize(*args) args.flatten! @first, @last = args.shift, args.pop @middle = args.join(' ') if args.any? super(to_s) end |
Instance Attribute Details
#first ⇒ Object (readonly)
Returns the value of attribute first.
3 4 5 |
# File 'lib/mongoid-name.rb', line 3 def first @first end |
#last ⇒ Object (readonly)
Returns the value of attribute last.
3 4 5 |
# File 'lib/mongoid-name.rb', line 3 def last @last end |
#middle ⇒ Object (readonly)
Returns the value of attribute middle.
3 4 5 |
# File 'lib/mongoid-name.rb', line 3 def middle @middle end |
Class Method Details
.demongoize(array) ⇒ Object
34 35 36 |
# File 'lib/mongoid-name.rb', line 34 def self.demongoize(array) new(*array) end |
.evolve(object) ⇒ Object
42 43 44 |
# File 'lib/mongoid-name.rb', line 42 def self.evolve(object) object.respond_to?(:mongoize) ? object.mongoize : object end |
.mongoize(object) ⇒ Object
38 39 40 |
# File 'lib/mongoid-name.rb', line 38 def self.mongoize(object) object.respond_to?(:mongoize) ? object.mongoize : object end |
Instance Method Details
#to_a ⇒ Object Also known as: mongoize
22 23 24 |
# File 'lib/mongoid-name.rb', line 22 def to_a [ first, middle, last ].compact end |
#to_h ⇒ Object
16 17 18 19 20 |
# File 'lib/mongoid-name.rb', line 16 def to_h { 'first' => first, 'middle' => middle, 'last' => last } end |
#to_s ⇒ Object
26 27 28 |
# File 'lib/mongoid-name.rb', line 26 def to_s to_a.join(' ') end |