Class: String
- Defined in:
- lib/jss/compatibility.rb,
lib/jss/ruby_extensions/string.rb
Instance Method Summary collapse
- #force_encoding(args = nil) ⇒ Object
-
#jss_integer? ⇒ Boolean
Is this string also a positive integer? (i.e. it consists only of numberic digits).
-
#jss_to_bool ⇒ Boolean?
Convert the strings “true” and “false” (after stripping whitespace and downcasing) to TrueClass and FalseClass respectively.
-
#jss_to_pathname ⇒ Pathname
Convert a String to a Pathname object.
-
#jss_to_time ⇒ Time
Convert a string to a Time object.
Instance Method Details
#force_encoding(args = nil) ⇒ Object
65 |
# File 'lib/jss/compatibility.rb', line 65 def force_encoding(args = nil); self; end |
#jss_integer? ⇒ Boolean
Is this string also a positive integer? (i.e. it consists only of numberic digits)
69 70 71 |
# File 'lib/jss/ruby_extensions/string.rb', line 69 def jss_integer? self =~ /\A[0-9]+\Z/ ? true : false end |
#jss_to_bool ⇒ Boolean?
Convert the strings “true” and “false” (after stripping whitespace and downcasing) to TrueClass and FalseClass respectively
Return nil if any other string.
37 38 39 40 41 42 |
# File 'lib/jss/ruby_extensions/string.rb', line 37 def jss_to_bool case strip.downcase when 'true' then true when 'false' then false end # case end |
#jss_to_pathname ⇒ Pathname
Convert a String to a Pathname object
60 61 62 |
# File 'lib/jss/ruby_extensions/string.rb', line 60 def jss_to_pathname Pathname.new self end |
#jss_to_time ⇒ Time
Convert a string to a Time object
returns nil if not parsable by JSS::parse_datetime
50 51 52 53 54 |
# File 'lib/jss/ruby_extensions/string.rb', line 50 def jss_to_time JSS.parse_time self rescue return nil end |