Module: Ritsu::Utility::Strings
Class Method Summary collapse
- .convert_whitespaces_to_spaces(str, options = {}) ⇒ Object
- .first(len, str) ⇒ Object
- .is_c_name?(str) ⇒ Boolean
- .is_underscore_case?(str) ⇒ Boolean
- .leading_spaces(str, options = {}) ⇒ Object
- .leading_whitespaces(str) ⇒ Object
Class Method Details
.convert_whitespaces_to_spaces(str, options = {}) ⇒ Object
28 29 30 31 |
# File 'lib/ritsu/utility/strings.rb', line 28 def convert_whitespaces_to_spaces(str, ={}) = {:soft_tab => 4}.merge() str.sub("\t", " "*[:soft_tab]).sub(/\n\r/, "") end |
.first(len, str) ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/ritsu/utility/strings.rb', line 14 def first(len, str) if str.length > count str[0..(len-1)] else str end end |
.is_c_name?(str) ⇒ Boolean
9 10 11 |
# File 'lib/ritsu/utility/strings.rb', line 9 def is_c_name?(str) str =~ /^[A-Za-z_]\w*$/ end |
.is_underscore_case?(str) ⇒ Boolean
4 5 6 |
# File 'lib/ritsu/utility/strings.rb', line 4 def is_underscore_case?(str) str =~ /^[a-z_][0-9a-z_]*$/ end |
.leading_spaces(str, options = {}) ⇒ Object
34 35 36 37 |
# File 'lib/ritsu/utility/strings.rb', line 34 def leading_spaces(str, ={}) Ritsu::Utility::Strings.convert_whitespaces_to_spaces( Ritsu::Utility::Strings.leading_whitespaces(str), ) end |
.leading_whitespaces(str) ⇒ Object
23 24 25 |
# File 'lib/ritsu/utility/strings.rb', line 23 def leading_whitespaces(str) /^\s*/.match(str)[0] end |