sleeping_king_studios-tools 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b84a20dc28755fec42bb26cad95995a68dcfa43b
4
- data.tar.gz: 4c8ec5eb136bae1f6a0de40ee35cc64aa247e277
3
+ metadata.gz: 219097e26ec6aeccbe9e62d239cf93e987807cd5
4
+ data.tar.gz: 3a216492307ed761a30bd827e6798318483fe81e
5
5
  SHA512:
6
- metadata.gz: 5a1778fea6d649db3f31b1e8d8ab82b2cf6195151effc106212d7c0abdc3ad6efd5dbafc2780f9f9b9ccee4f80762f1db57682135be53a7da1c7b690cef5d048
7
- data.tar.gz: fb94d1674d718cab7539bc71a9e78dcc9c578bbf91d859192ccf432fec29b8913c7220e8d46d8b800b5e0c1fd75a7c41330c285b6a44695b3d67cfeb0adf9273
6
+ metadata.gz: 5c9b6cfb2b0d45f7f93b22fa47a589b2428983520a4c9f87afd2d5498b15ba629ad8c34d9eae9e2b1abb8db3eca342b9795b53fdf3dfd0655c6151220c6b7e62
7
+ data.tar.gz: bd52cc9727fb36e02686f3c23428439b645a946d405962e2c7e3eae7c14c85fdfc6d4e8af5ad4a17969c895ba3c11178e1af3ec4846ee00e5f41a8117806cff2
@@ -59,20 +59,41 @@ module SleepingKingStudios::Tools
59
59
  # ArrayTools.humanize_list(['spam', 'eggs', 'bacon', 'spam'])
60
60
  # #=> 'spam, eggs, bacon, and spam'
61
61
  #
62
+ # @example With Three Or More Items And Options
63
+ # ArrayTools.humanize_list(['spam', 'eggs', 'bacon', 'spam'], :last_separator => ' or ')
64
+ # #=> 'spam, eggs, bacon, or spam'
65
+ #
62
66
  # @param [Array<String>] values The list of values to format. Will be
63
67
  # coerced to strings using #to_s.
68
+ # @param [Hash] options Optional configuration hash.
69
+ # @option options [String] :last_separator The value to use to separate
70
+ # the final pair of values. Defaults to " and " (note the leading and
71
+ # trailing spaces). Will be combined with the :separator for lists of
72
+ # length 3 or greater.
73
+ # @option options [String] :separator The value to use to separate pairs
74
+ # of values before the last in lists of length 3 or greater. Defaults to
75
+ # ", " (note the trailing space).
64
76
  #
65
77
  # @return [String] The formatted string.
66
- def humanize_list values
78
+ def humanize_list values, options = {}
79
+ separator = options.fetch(:separator, ', ')
80
+ last_separator = options.fetch(:last_separator, ' and ')
81
+
67
82
  case values.count
68
83
  when 0
69
84
  ''
70
85
  when 1
71
86
  values.first.to_s
72
87
  when 2
73
- "#{values.first} and #{values.last}"
88
+ "#{values[0]}#{last_separator}#{values[1]}"
74
89
  else
75
- "#{values[0...-1].join(', ')}, and #{values.last}"
90
+ if last_separator =~ /\A,?\s*/
91
+ last_separator = last_separator.sub /\A,?\s*/, separator
92
+ else
93
+ last_separator = "#{separator}#{last_separator}"
94
+ end # if-else
95
+
96
+ "#{values[0...-1].join(separator)}#{last_separator}#{values.last}"
76
97
  end # case
77
98
  end # method humanize_list
78
99
  end # module
@@ -12,7 +12,7 @@ module SleepingKingStudios
12
12
 
13
13
  MAJOR = 0
14
14
  MINOR = 1
15
- PATCH = 0
15
+ PATCH = 1
16
16
  end # module
17
17
 
18
18
  VERSION = Version.to_gem_version
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sleeping_king_studios-tools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rob "Merlin" Smith