Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/openstudio_measure_tester/core_ext.rb

Overview

******************************************************************************* OpenStudio®, Copyright © Alliance for Sustainable Energy, LLC. See also openstudio.net/license *******************************************************************************

Instance Method Summary collapse

Instance Method Details

#titleizeObject

simple method to create titles – very custom to catch known inflections



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/openstudio_measure_tester/core_ext.rb', line 28

def titleize
  arr = ['a', 'an', 'the', 'by', 'to']
  upcase_arr = ['DX', 'EDA', 'AEDG', 'LPD', 'COP', 'GHLEP', 'ZEDG', 'QAQC', 'PV']
  r = tr('_', ' ').gsub(/\w+/) do |match|
    match_result = match
    if upcase_arr.include?(match.upcase)
      match_result = upcase_arr[upcase_arr.index(match.upcase)]
    elsif arr.include?(match)
      match_result = match
    else
      match_result = match.capitalize
    end
    match_result
  end

  # fix a couple known camelcase versions
  r.gsub!('Energyplus', 'EnergyPlus')
  r.gsub!('Openstudio', 'OpenStudio')
  r
end

#to_camelcaseObject



20
21
22
23
24
25
# File 'lib/openstudio_measure_tester/core_ext.rb', line 20

def to_camelcase
  r = split('_').collect(&:capitalize).join
  r.gsub!('Energyplus', 'EnergyPlus')
  r.gsub!('Openstudio', 'OpenStudio')
  r
end

#to_snakecaseObject



9
10
11
12
13
14
15
16
17
18
# File 'lib/openstudio_measure_tester/core_ext.rb', line 9

def to_snakecase
  r = gsub(/::/, '/')
      .gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
      .gsub(/([a-z\d])([A-Z])/, '\1_\2')
      .tr('-', '_')
      .downcase
  r.gsub!('energy_plus', 'energyplus')
  r.gsub!('open_studio', 'openstudio')
  r
end