Class: String

Inherits:
Object show all
Defined in:
lib/trellis/utils.rb

Overview

:nodoc:

Constant Summary collapse

PLURALS =
[['(quiz)$', '\1zes'],['(ox)$', '\1en'],['([m|l])ouse$', '\1ice'],['(matr|vert|ind)ix|ex$', '\1ices'],
['(x|ch|ss|sh)$', '\1es'],['([^aeiouy]|qu)ies$', '\1y'],['([^aeiouy]|q)y$$', '\1ies'],['(hive)$', '\1s'],
['(?:[^f]fe|([lr])f)$', '\1\2ves'],['(sis)$', 'ses'],['([ti])um$', '\1a'],['(buffal|tomat)o$', '\1oes'],['(bu)s$', '\1es'],
['(alias|status)$', '\1es'],['(octop|vir)us$', '\1i'],['(ax|test)is$', '\1es'],['s$', 's'],['$', 's']]
SINGULARS =
[['(quiz)zes$', '\1'],['(matr)ices$', '\1ix'],['(vert|ind)ices$', '\1ex'],['^(ox)en$', '\1'],['(alias|status)es$', '\1'],
['(octop|vir)i$', '\1us'],['(cris|ax|test)es$', '\1is'],['(shoe)s$', '\1'],['[o]es$', '\1'],['[bus]es$', '\1'],['([m|l])ice$', '\1ouse'],
['(x|ch|ss|sh)es$', '\1'],['(m)ovies$', '\1ovie'],['[s]eries$', '\1eries'],['([^aeiouy]|qu)ies$', '\1y'],['[lr]ves$', '\1f'],
['(tive)s$', '\1'],['(hive]s$', '\1'],['([^f]]ves$', '\1fe'],['(^analy)ses$', '\1sis'],
['([a]naly|[b]a|[d]iagno|[p]arenthe|[p]rogno|[s]ynop|[t]he)ses$', '\1\2sis'],['([ti])a$', '\1um'],['(news)$', '\1ews']]

Instance Method Summary collapse

Instance Method Details

#blank?Boolean

Returns:

  • (Boolean)


120
121
122
# File 'lib/trellis/utils.rb', line 120

def blank?
  self !~ /\S/
end

#humanizeObject



139
140
141
# File 'lib/trellis/utils.rb', line 139

def humanize
  gsub(/_id$/, "").gsub(/_/, " ").capitalize
end

#pluralObject



111
112
113
# File 'lib/trellis/utils.rb', line 111

def plural()
  PLURALS.each { |match_exp, replacement_exp| return gsub(Regexp.compile(match_exp), replacement_exp) unless match(Regexp.compile(match_exp)).nil? }
end

#plural?Boolean

Returns:

  • (Boolean)


115
116
117
118
# File 'lib/trellis/utils.rb', line 115

def plural?
  PLURALS.each {|match_exp, replacement_exp| return true if match(Regexp.compile(match_exp))}
  false
end

#replace_ant_style_properties(properties) ⇒ Object



131
132
133
134
135
136
137
# File 'lib/trellis/utils.rb', line 131

def replace_ant_style_properties(properties)
  text = self
  properties.each_pair do |key,value|
    text = text.replace_ant_style_property(key, value)
  end
  text
end

#replace_ant_style_property(property, value) ⇒ Object



124
125
126
127
128
129
# File 'lib/trellis/utils.rb', line 124

def replace_ant_style_property(property, value)
  result = self.gsub(/\$\{#{property.to_s}\}/) do |match|
    value
  end
  result
end

#singularObject



107
108
109
# File 'lib/trellis/utils.rb', line 107

def singular()
  SINGULARS.each { |match_exp, replacement_exp| return gsub(Regexp.compile(match_exp), replacement_exp) unless match(Regexp.compile(match_exp)).nil?}
end