Class: Gaku::PersonDecorator
- Inherits:
-
Draper::Decorator
- Object
- Draper::Decorator
- Gaku::PersonDecorator
show all
- Defined in:
- app/decorators/gaku/person_decorator.rb
Instance Method Summary
collapse
Instance Method Details
returns full name complete with formatting [if any]
9
10
11
|
# File 'app/decorators/gaku/person_decorator.rb', line 9
def formatted_name
student_names
end
|
13
14
15
|
# File 'app/decorators/gaku/person_decorator.rb', line 13
def formatted_name_reading
student_names reading: true
end
|
#full_name ⇒ Object
return full name without formatting but in order, with spaces between portions
19
20
21
|
# File 'app/decorators/gaku/person_decorator.rb', line 19
def full_name
student_names without_formating: true
end
|
#full_name_reading ⇒ Object
23
24
25
|
# File 'app/decorators/gaku/person_decorator.rb', line 23
def full_name_reading
student_names without_formating: true, reading: true
end
|
#sex_and_birth ⇒ Object
4
5
6
|
# File 'app/decorators/gaku/person_decorator.rb', line 4
def sex_and_birth
[h.gender(object), object.birth_date.to_s].reject(&:empty?).join(', ')
end
|
#student_names(options = {}) ⇒ Object
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
# File 'app/decorators/gaku/person_decorator.rb', line 27
def student_names(options = {})
@names_preset ||= Gaku::Preset.names
preset = @names_preset
if options[:without_formating]
preset_without_format = ''
preset.gsub(/%(\w+)/) {|n| preset_without_format << n + ' '}
preset = preset_without_format.strip
end
if options[:reading] && object.name_reading.blank? && object.surname_reading.blank? && object.middle_name_reading.blank?
return ''
end
reading = options[:reading]
if preset.blank?
return reading ? object.phonetic_reading : object.to_s
end
result = preset.gsub(/%(\w+)/) do |name|
case name
when '%first' then proper_name(:name, reading)
when '%middle' then proper_name(:middle_name, reading)
when '%last' then proper_name(:surname, reading)
end
end
return result.gsub(/[^[[:word:]]\s]/, '').gsub(/\s+/, ' ').strip if object.middle_name.blank?
result.gsub(/\s+/, ' ').strip
end
|