Class: String
Instance Method Summary collapse
- #camelize(first_letter_in_uppercase = true) ⇒ Object
- #constantize ⇒ Object
- #to_color ⇒ Object
- #to_pixels ⇒ Object
- #underscore ⇒ Object
Instance Method Details
#camelize(first_letter_in_uppercase = true) ⇒ Object
3 4 5 6 7 8 9 |
# File 'lib/droiuby/support/string.rb', line 3 def camelize(first_letter_in_uppercase = true) if first_letter_in_uppercase self.to_s.gsub(/\/(.?)/) { "::" + $1.upcase }.gsub(/(^|_)(.)/) { $2.upcase } else self.first + camelize(self)[1..-1] end end |
#constantize ⇒ Object
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/droiuby/support/string.rb', line 27 def constantize names = self.split('::') names.shift if names.empty? || names.first.empty? constant = Object names.each do |name| constant = constant.const_defined?(name) ? constant.const_get(name) : constant.const_missing(name) end constant end |
#to_color ⇒ Object
15 16 17 |
# File 'lib/droiuby/support/string.rb', line 15 def to_color Java::android.graphics.Color.parseColor(self) end |
#to_pixels ⇒ Object
11 12 13 |
# File 'lib/droiuby/support/string.rb', line 11 def to_pixels Java::com.droiuby.client.core.builder.ActivityBuilder.toPixels(_current_activity, self) end |
#underscore ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/droiuby/support/string.rb', line 19 def underscore self.gsub(/::/, '/'). gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2'). gsub(/([a-z\d])([A-Z])/,'\1_\2'). tr("-", "_"). downcase end |