class String
Public Instance Methods
camel_case()
click to toggle source
Converts a string to camelCase.
# File lib/cucumber/helpers/core_ext.rb, line 92 def camel_case s = self s = s.snake_case unless /^[a-z0-9]+$/i =~ s s = s.downcase if s == s.upcase # stop "CVV" -> "cVV" when it should be "cvv" s.camelize(:lower) end
snake_case(casing = :lower)
click to toggle source
Converts a string to snake_case
or SNAKE_CASE.
# File lib/cucumber/helpers/core_ext.rb, line 100 def snake_case(casing = :lower) s = self.tr(" ", "_") case casing when :lower then s.downcase when :upper then s.upcase else raise ArgumentError, "unsupported casing" end end
to_type(type)
click to toggle source
Converts a string to the specified primitive type. Useful because all Gherkin values are treated as strings.
# File lib/cucumber/helpers/core_ext.rb, line 110 def to_type(type) # note: cannot use 'case type' as that expands to === which checks for instances of rather than type equality if type == Boolean self == "true" elsif type == Date Date.parse(self) elsif type == DateTime DateTime.parse(self) elsif type == Enum self.snake_case(:upper) elsif type == Float self.to_f elsif type == Integer self.to_i else self end end