Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/mail/core_extensions/string.rb,
lib/mail/vendor/treetop-1.4.3/lib/treetop/ruby_extensions/string.rb
Overview
:nodoc:
Constant Summary collapse
- US_ASCII_REGEXP =
Provides all strings with the Ruby 1.9 method of .ascii_only? and returns true or false
%Q{\x00-\x7f}
Instance Method Summary collapse
- #ascii_only? ⇒ Boolean
- #blank? ⇒ Boolean
- #column_of(index) ⇒ Object
- #indent(n) ⇒ Object
- #line_of(index) ⇒ Object
-
#tabto(n) ⇒ Object
The following methods are lifted from Facets 2.0.2.
- #to_crlf ⇒ Object
- #to_lf ⇒ Object
- #treetop_camelize ⇒ Object
Instance Method Details
#ascii_only? ⇒ Boolean
15 16 17 |
# File 'lib/mail/core_extensions/string.rb', line 15 def ascii_only? !(self =~ /[^#{US_ASCII_REGEXP}]/) end |
#blank? ⇒ Boolean
17 18 19 |
# File 'lib/mail/vendor/treetop-1.4.3/lib/treetop/ruby_extensions/string.rb', line 17 def blank? self == "" end |
#column_of(index) ⇒ Object
2 3 4 5 6 7 8 9 10 |
# File 'lib/mail/vendor/treetop-1.4.3/lib/treetop/ruby_extensions/string.rb', line 2 def column_of(index) return 1 if index == 0 newline_index = rindex("\n", index - 1) if newline_index index - newline_index else index + 1 end end |
#indent(n) ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/mail/vendor/treetop-1.4.3/lib/treetop/ruby_extensions/string.rb', line 31 def indent(n) if n >= 0 gsub(/^/, ' ' * n) else gsub(/^ {0,#{-n}}/, "") end end |
#line_of(index) ⇒ Object
12 13 14 |
# File 'lib/mail/vendor/treetop-1.4.3/lib/treetop/ruby_extensions/string.rb', line 12 def line_of(index) self[0...index].count("\n") + 1 end |
#tabto(n) ⇒ Object
The following methods are lifted from Facets 2.0.2
23 24 25 26 27 28 29 |
# File 'lib/mail/vendor/treetop-1.4.3/lib/treetop/ruby_extensions/string.rb', line 23 def tabto(n) if self =~ /^( *)\S/ indent(n - $1.length) else self end end |
#to_crlf ⇒ Object
3 4 5 |
# File 'lib/mail/core_extensions/string.rb', line 3 def to_crlf gsub(/\n|\r\n|\r/) { "\r\n" } end |
#to_lf ⇒ Object
7 8 9 |
# File 'lib/mail/core_extensions/string.rb', line 7 def to_lf gsub(/\n|\r\n|\r/) { "\n" } end |
#treetop_camelize ⇒ Object
39 40 41 |
# File 'lib/mail/vendor/treetop-1.4.3/lib/treetop/ruby_extensions/string.rb', line 39 def treetop_camelize to_s.gsub(/\/(.?)/){ "::" + $1.upcase }.gsub(/(^|_)(.)/){ $2.upcase } end |