bcl 0.5.3 → 0.5.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/bcl/core_ext.rb CHANGED
@@ -1,15 +1,47 @@
1
+ ######################################################################
2
+ # Copyright (c) 2008-2014, Alliance for Sustainable Energy.
3
+ # All rights reserved.
4
+ #
5
+ # This library is free software; you can redistribute it and/or
6
+ # modify it under the terms of the GNU Lesser General Public
7
+ # License as published by the Free Software Foundation; either
8
+ # version 2.1 of the License, or (at your option) any later version.
9
+ #
10
+ # This library is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
+ # Lesser General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU Lesser General Public
16
+ # License along with this library; if not, write to the Free Software
17
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
+ ######################################################################
19
+
1
20
  class String
2
21
  def to_underscore
3
- self.gsub(/::/, '/').
22
+ gsub(/::/, '/').
4
23
  gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2').
5
24
  gsub(/([a-z\d])([A-Z])/, '\1_\2').
6
- tr("-", "_").
25
+ tr('-', '_').
7
26
  downcase
8
27
  end
9
28
 
10
- # simple method to create titles
29
+ # simple method to create titles -- very custom to catch known inflections
11
30
  def titleize
12
- arr = ['a', 'an', 'the']
13
- self.gsub('_', ' ').gsub(/\w+/) { |match| arr.include?(match) ? match : match.capitalize }
31
+ arr = %w(a an the by to)
32
+ upcase_arr = %w(DX EDA AEDG LPD COP)
33
+ r = gsub('_', ' ').gsub(/\w+/) { |match|
34
+ match_result = match
35
+ if upcase_arr.include?(match.upcase)
36
+ match_result = upcase_arr[upcase_arr.index(match.upcase)]
37
+ elsif arr.include?(match)
38
+ match_result = match
39
+ else
40
+ match_result = match.capitalize
41
+ end
42
+ match_result
43
+ }
44
+
45
+ r
14
46
  end
15
- end
47
+ end