class Mongoid::Name

Attributes

first[R]
last[R]
middle[R]

Public Class Methods

demongoize(array) click to toggle source
# File lib/mongoid-name.rb, line 34
def self.demongoize(array)
  new(*array)
end
evolve(object) click to toggle source
# File lib/mongoid-name.rb, line 42
def self.evolve(object)
  object.respond_to?(:mongoize) ? object.mongoize : object
end
mongoize(object) click to toggle source
# File lib/mongoid-name.rb, line 38
def self.mongoize(object)
  object.respond_to?(:mongoize) ? object.mongoize : object
end
new(*args) click to toggle source

Name.new(‘AJ’, ‘Ostrow’) Name.new(‘Alexander’, ‘Jacob’, ‘Ostrow’) Name.new(%w(AJ Ostrow)) Name.new(%w(Alexander Jacob Ostrow))

Calls superclass method
# 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

Public Instance Methods

mongoize()

Mongoid conversions

Alias for: to_a
to_a() click to toggle source
# File lib/mongoid-name.rb, line 22
def to_a
  [ first, middle, last ].compact
end
Also aliased as: mongoize
to_h() click to toggle source
# File lib/mongoid-name.rb, line 16
def to_h
  { 'first' => first,
    'middle' => middle,
    'last' => last }
end
to_s() click to toggle source
# File lib/mongoid-name.rb, line 26
def to_s
  to_a.join(' ')
end