Class: Mustache::Utils::String
- Inherits:
-
Object
- Object
- Mustache::Utils::String
- Defined in:
- lib/mustache/utils.rb
Instance Method Summary collapse
- #classify ⇒ Object
-
#initialize(string) ⇒ String
constructor
A new instance of String.
- #underscore(view_namespace) ⇒ Object
Constructor Details
#initialize(string) ⇒ String
Returns a new instance of String.
4 5 6 |
# File 'lib/mustache/utils.rb', line 4 def initialize string @string = string end |
Instance Method Details
#classify ⇒ Object
8 9 10 11 12 13 14 15 |
# File 'lib/mustache/utils.rb', line 8 def classify @string.split('/').map do |namespace| namespace.split(/[-_]/).map do |part| part[0] = part.chars.first.upcase part end.join end.join('::') end |
#underscore(view_namespace) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/mustache/utils.rb', line 17 def underscore(view_namespace) @string .dup .split("#{view_namespace}::") .last .split('::') .map do |part| part[0] = part[0].downcase part.gsub(/[A-Z]/) { |s| "_" << s.downcase } end .join('/') end |