class String
Constants
- Alpha26
Public Instance Methods
clean_whitespace()
click to toggle source
# File lib/creative_rails_utilities/string.rb, line 15 def clean_whitespace return strip.gsub(/\s{2,}/, ' ') end
to_bool()
click to toggle source
Convert string to boolean.
# File lib/creative_rails_utilities/string.rb, line 24 def to_bool return true if self[/\A(true)|(1)|(y(es)?)\z/i] return false if self[/\A(false)|(0)|(no?)|(nil)\z/i] || self == "" raise(ArgumentError.new "could not interpret '#{self}' as boolean.") end
to_i26()
click to toggle source
# File lib/creative_rails_utilities/string.rb, line 5 def to_i26 result = 0 downcase! (1..length).each do |i| char = self[-i] result += 26**(i-1) * (Alpha26.index(char) + 1) end result end
to_query_hash()
click to toggle source
convert an URI
query string into a symbol hash, does not support array query records (yet)
# File lib/creative_rails_utilities/string.rb, line 31 def to_query_hash raise ArgumentError.new("Looks like unsupported array query is used, sorry!") if self.to_s[/\[\]\=/].present? query_hash = split("&").reduce({}) do |mem, i| key = i.split("=").first value = i.split("=").second mem[key.to_s] = value.to_s mem end return query_hash end
unindent()
click to toggle source
# File lib/creative_rails_utilities/string.rb, line 19 def unindent gsub(/^#{self[/\A\s*/]}/, '') end