class String
Cast a string to an id.
Public Instance Methods
to_date_id()
click to toggle source
Cast me to a date id.
" 2000-12-31 ".to_date_id #=> "2000-12-31"
# File lib/sixarm_ruby_to_id/string.rb, line 11 def to_date_id s = self.strip s =~ /\A\d\d\d\d-\d\d-\d\d\z/ ? s : nil end
to_date_ids()
click to toggle source
Cast me to a list of date ids. The string is comma-separated.
"2000-12-31,2001-12-31,2002-12-31".to_date_id #=> ["2000-12-31", "2001-12-31", "2002-12-31"]
# File lib/sixarm_ruby_to_id/string.rb, line 22 def to_date_ids split(/,/).map{|x| x.to_date_id} end
to_i_id()
click to toggle source
Cast me to an integer id.
" 1 ".to_i_id #=> 1
# File lib/sixarm_ruby_to_id/string.rb, line 64 def to_i_id strip.to_i end
to_i_ids()
click to toggle source
Cast me (a comma-separated list) to a list of integer ids. The string is comma-separated.
"1,2,3".to_s_ids #=> [1, 2, 3]
# File lib/sixarm_ruby_to_id/string.rb, line 74 def to_i_ids split(/,/).map{|x| x.to_i_id} end
to_s_id()
click to toggle source
Cast me to a string id.
" a " #=> "a"
# File lib/sixarm_ruby_to_id/string.rb, line 83 def to_s_id strip end
to_s_ids()
click to toggle source
Cast me to a list of string ids. The string is comma-separated.
"a,b,c".to_s_ids #=> ["a", "b", "c"]
# File lib/sixarm_ruby_to_id/string.rb, line 93 def to_s_ids split(/,/).to_s_ids end
to_s_uuid()
click to toggle source
Cast me to a string uuid.
" 00000000-0000-0000-0000-000000000000 ".to_s_uuids #=> "00000000-0000-0000-0000-000000000000"
# File lib/sixarm_ruby_to_id/string.rb, line 102 def to_s_uuid strip.match(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/) ? $& : nil end
to_s_uuids()
click to toggle source
Cast me to a list of string ids. The string is comma-separated.
"00000000-0000-0000-0000-000000000000,11111111-1111-1111-1111-111111111111".to_s_uuids #=> [ "00000000-0000-0000-0000-000000000000" "11111111-1111-1111-1111-111111111111" ]
# File lib/sixarm_ruby_to_id/string.rb, line 115 def to_s_uuids split(/,/).to_s_uuids end
to_stint_id()
click to toggle source
Cast me to a stint id.
The string is two ISO dates in YYYY-MM-DD.
The separator is either:
* two dots ".." to include the stop date * three dots "..." to exclude the stop date.
Examples:
" 2000-12-30..2000-12-31".to_stint_id #=> "2000-12-30-2000-12-31" " 2000-12-30...2000-12-31".to_stint_id #=> "2000-12-30-2000-12-31"
# File lib/sixarm_ruby_to_id/string.rb, line 44 def to_stint_id s = self.strip s =~ /\A\d\d\d\d-\d\d-\d\d\.\.\.?\d\d\d\d-\d\d-\d\d\z/ ? s : nil end
to_stint_ids()
click to toggle source
Cast me to a list of stint ids. The string is comma-separated.
"2000-12-30-2000-12-31,2001-12-30-2001-12-31,2002-12-30-2002-12-31".to_date_id #=> ["2000-12-30-2000-12-31"], ["2001-12-30-2001-12-31"], ["2002-12-30-2002-12-31"]]
# File lib/sixarm_ruby_to_id/string.rb, line 55 def to_stint_ids split(/,/).map{|x| x.to_stint_id} end