Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/ironnails/core_ext/string.rb
Instance Method Summary collapse
- #camelize(first_letter_in_uppercase = true) ⇒ Object
- #classify ⇒ Object
- #decrypt ⇒ Object
-
#ensure_http ⇒ Object
ensures that our url starts with at least http.
-
#is_url? ⇒ Boolean
returns whether this string is a well formed url.
- #strip_html ⇒ Object
- #to_clr_char ⇒ Object
- #to_secure_string ⇒ Object
- #truncate(max = 140) ⇒ Object
- #underscore ⇒ Object
Instance Method Details
#camelize(first_letter_in_uppercase = true) ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/ironnails/core_ext/string.rb', line 18 def camelize(first_letter_in_uppercase = true) if first_letter_in_uppercase self.to_s.gsub(/\/(.?)/) { "::" + $1.upcase }.gsub(/(^|_)(.)/) { $2.upcase } else self[0...1].downcase + camelize(self)[1..-1] end end |
#classify ⇒ Object
46 47 48 |
# File 'lib/ironnails/core_ext/string.rb', line 46 def classify Kernel.const_get(self.camelize) end |
#decrypt ⇒ Object
42 43 44 |
# File 'lib/ironnails/core_ext/string.rb', line 42 def decrypt IronNails::Security::SecureString.decrypt_string self end |
#ensure_http ⇒ Object
ensures that our url starts with at least http
4 5 6 7 |
# File 'lib/ironnails/core_ext/string.rb', line 4 def ensure_http return "http://#{self}" unless /^(ht|f)tp:\/\/.*/i.match(self) self end |
#is_url? ⇒ Boolean
returns whether this string is a well formed url
10 11 12 |
# File 'lib/ironnails/core_ext/string.rb', line 10 def is_url? !!(Uri.is_well_formed_uri_string(self.to_clr_string, UriKind.Absolute) && /^(ht|f)tp/i.match(Uri.new(self).scheme)) end |
#strip_html ⇒ Object
14 15 16 |
# File 'lib/ironnails/core_ext/string.rb', line 14 def strip_html self.gsub(/<(.|\n)*?>/, '') end |
#to_clr_char ⇒ Object
34 35 36 |
# File 'lib/ironnails/core_ext/string.rb', line 34 def to_clr_char self.to_clr_string.to_char_array[0] end |
#to_secure_string ⇒ Object
38 39 40 |
# File 'lib/ironnails/core_ext/string.rb', line 38 def to_secure_string IronNails::Security::SecureString.secure_string self end |
#truncate(max = 140) ⇒ Object
50 51 52 53 54 55 56 |
# File 'lib/ironnails/core_ext/string.rb', line 50 def truncate(max=140) if self.size > max s = self[0...max-5] return s.split(' ')[0...s.split(' ').size - 1].join(' ') end self end |
#underscore ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/ironnails/core_ext/string.rb', line 26 def underscore self.gsub(/::/, '/'). gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2'). gsub(/([a-z\d])([A-Z])/, '\1_\2'). tr("-", "_"). downcase end |