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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/full_name.rb +33 -16
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4d922e261990297dd4fb0d185e0ff433cafb2898
4
- data.tar.gz: 047931817f810b2619966608d669cb3a2c1b6f9b
3
+ metadata.gz: 380c6dcbcf7db77499747dd133ce3b8b3a8d34b1
4
+ data.tar.gz: 472518bf2649bae7e3bfb26d6a44ecd403a14fce
5
5
  SHA512:
6
- metadata.gz: f3a6821683a2b84766169e7cf2622b8bcfb7885d65c7e1195ce7c7bf43c8ec7b19507a207292725d2b98f67580be0a354110c4de5b55e5465206d6af9279c025
7
- data.tar.gz: 7d6e510e0dd9d69c46844a1ad7b9b89839b36f7296170f6a4c7fc58a8cd1ffea0cbbe0891f53806641b3ddf6ce5d2f98c2e92453d9c059e29a37b6923a155d0d
6
+ metadata.gz: 89ad8f9a5f3d88ddffed8318675e16a97594c3ab33787d5270a202d191f31e041195d1261e5dff0cd06dabadeef2e313e769115cd2d83a02792232b34f103929
7
+ data.tar.gz: f6ad1ab5c4b08e0fd133fa4430b3c0a52fda2e967859f16cbdaddda719b7dd6e72a5261ccac50455c09a061f5a1363e6ad1a331a8f2dee71cdef2739f984b9ae
@@ -1,29 +1,46 @@
1
1
  module FullName
2
+ LOCALES = [:en, :fr]
3
+
2
4
  def full_name locale = :en
3
- if locale != :en and locale != :fr
4
- return full_name(:en)
5
- end
5
+ return full_name unless LOCALES.include? locale
6
6
 
7
- if first_name and first_name.size > 0
8
- if last_name and last_name.size > 0
9
- case locale
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
- full_name = first_name.capitalize
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
- full_name = last_name.capitalize
26
+ [first_name.capitalize, last_name.capitalize].join(' ')
23
27
  when :fr then
24
- full_name = last_name.upcase
28
+ "#{last_name.upcase}, #{first_name.capitalize}"
25
29
  end
26
30
  end
27
- end
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
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: full_name
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Benoit Gantaume