module Caseninja
Constants
- VERSION
Public Instance Methods
normalize(text)
click to toggle source
# File lib/caseninja.rb, line 41 def normalize(text) if text =~ / / text.downcase elsif text =~ /-/ text.gsub("-", " ").downcase elsif text =~ /_/ text.gsub("_", " ").downcase else text.split(/(?=[A-Z])/).join(" ").downcase end end
to_camel(text)
click to toggle source
# File lib/caseninja.rb, line 25 def to_camel(text) to_pascal(text).sub(/./) { $&.downcase } end
to_chain(text)
click to toggle source
# File lib/caseninja.rb, line 17 def to_chain(text) normalize(text).gsub(" ", "-") end
to_hash(text)
click to toggle source
# File lib/caseninja.rb, line 6 def to_hash(text) { chain: to_chain(text), snake: to_snake(text), camel: to_camel(text), pascal: to_pascal(text), upchain: to_upchain(text), upsnake: to_upsnake(text), } end
to_pascal(text)
click to toggle source
# File lib/caseninja.rb, line 29 def to_pascal(text) normalize(text).split.map { |e| e.capitalize }.join end
to_snake(text)
click to toggle source
# File lib/caseninja.rb, line 21 def to_snake(text) normalize(text).gsub(" ", "_") end
to_upchain(text)
click to toggle source
# File lib/caseninja.rb, line 33 def to_upchain(text) to_chain(text).upcase end
to_upsnake(text)
click to toggle source
# File lib/caseninja.rb, line 37 def to_upsnake(text) to_snake(text).upcase end