full_name 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/full_name.rb +33 -16
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 380c6dcbcf7db77499747dd133ce3b8b3a8d34b1
|
4
|
+
data.tar.gz: 472518bf2649bae7e3bfb26d6a44ecd403a14fce
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 89ad8f9a5f3d88ddffed8318675e16a97594c3ab33787d5270a202d191f31e041195d1261e5dff0cd06dabadeef2e313e769115cd2d83a02792232b34f103929
|
7
|
+
data.tar.gz: f6ad1ab5c4b08e0fd133fa4430b3c0a52fda2e967859f16cbdaddda719b7dd6e72a5261ccac50455c09a061f5a1363e6ad1a331a8f2dee71cdef2739f984b9ae
|
data/lib/full_name.rb
CHANGED
@@ -1,29 +1,46 @@
|
|
1
1
|
module FullName
|
2
|
+
LOCALES = [:en, :fr]
|
3
|
+
|
2
4
|
def full_name locale = :en
|
3
|
-
|
4
|
-
return full_name(:en)
|
5
|
-
end
|
5
|
+
return full_name unless LOCALES.include? locale
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
when :en then
|
11
|
-
full_name = [first_name.capitalize, last_name.capitalize].join(' ')
|
12
|
-
when :fr then
|
13
|
-
full_name = "#{last_name.upcase}, #{first_name.capitalize}"
|
14
|
-
end
|
15
|
-
|
7
|
+
unless first_name.nil? or first_name.empty?
|
8
|
+
unless last_name.nil? or last_name.empty?
|
9
|
+
build_with_both locale
|
16
10
|
else
|
17
|
-
|
11
|
+
build_with_firstname
|
18
12
|
end
|
19
13
|
else
|
14
|
+
unless last_name.nil? or last_name.empty?
|
15
|
+
build_with_lastname locale
|
16
|
+
else
|
17
|
+
''
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
def build_with_both locale
|
20
24
|
case locale
|
21
25
|
when :en then
|
22
|
-
|
26
|
+
[first_name.capitalize, last_name.capitalize].join(' ')
|
23
27
|
when :fr then
|
24
|
-
|
28
|
+
"#{last_name.upcase}, #{first_name.capitalize}"
|
25
29
|
end
|
26
30
|
end
|
27
|
-
|
31
|
+
|
32
|
+
def build_with_firstname
|
33
|
+
first_name.capitalize
|
34
|
+
end
|
35
|
+
|
36
|
+
def build_with_lastname locale
|
37
|
+
case locale
|
38
|
+
when :en then
|
39
|
+
last_name.capitalize
|
40
|
+
when :fr then
|
41
|
+
last_name.upcase
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
28
45
|
end
|
29
46
|
|