lib/openwfe/utils.rb in openwferu-0.9.6 vs lib/openwfe/utils.rb in openwferu-0.9.7
- old
+ new
@@ -154,11 +154,28 @@
def OpenWFE.to_dash (string)
string.gsub("_", "-")
end
+ def OpenWFE.symbol_to_name (symbol)
+ to_dash(symbol.to_s)
+ end
+
+ def OpenWFE.name_to_symbol (name)
+ return name if name.is_a?(Symbol)
+ return to_underscore(name).intern
+ end
+
#
+ # Turns all the spaces in string into underscores.
+ # Returns the new String.
+ #
+ def OpenWFE.stu (s)
+ s.gsub("\s", "_")
+ end
+
+ #
# Returns an URI if the string is one, else returns nil.
# No exception is thrown by this method.
#
def OpenWFE.parse_uri (string)
begin
@@ -269,9 +286,19 @@
# Returns the number of milliseconds since this Timer was
# instantiated.
#
def duration
return (Time.now.to_f - @start) * 1000
+ end
+ end
+
+
+ #
+ # A simple Hash that accepts String or Symbol as lookup keys []
+ #
+ class SymbolHash < Hash
+ def [] (key)
+ super(key.to_s)
end
end
#
# Returns a version of s that is usable as or within a filename