Class: CustomNameOfPerson::PersonName

Inherits:
NameOfPerson::PersonName
  • Object
show all
Defined in:
app/models/spree/user_decorator.rb

Instance Method Summary collapse

Instance Method Details

#fullObject



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'app/models/spree/user_decorator.rb', line 3

def full
  @full ||= begin
    field_suffixes = I18n.t('address_format_i18n.field_suffixes', default: {})
    suffix = field_suffixes['fn'] || field_suffixes[:fn] || ''

    order = I18n.t("address_format_i18n.address.full_name", default: %w[first_name last_name])
    parts = order.map do |part|
      case part.to_s.downcase
      when "first_name" then first.to_s.strip
      when "last_name" then last.to_s.strip
      else nil
      end
    end.compact.join(" ").strip

    base_name = parts.blank? ? first.to_s.strip : parts
    base_name += " #{suffix}" if suffix
    base_name
  end
end

#to_sObject

to_sメソッドもオーバーライドして、デフォルトでfullを返すように



24
25
26
# File 'app/models/spree/user_decorator.rb', line 24

def to_s
  full
end