Module: Resourceful::Extensions::String
- Included in:
- String
- Defined in:
- lib/resourceful/extensions.rb
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
-
#constantize ⇒ Object
Ruby 1.9 version.
- #from_currency_to_f ⇒ Object
- #to_date ⇒ Object
- #to_datetime ⇒ Object
- #to_resourceful_boolean ⇒ Object
Class Method Details
.included(klass) ⇒ Object
28 29 30 |
# File 'lib/resourceful/extensions.rb', line 28 def self.included(klass) klass.extend(ClassMethods) if klass.kind_of?(Class) end |
Instance Method Details
#constantize ⇒ Object
Ruby 1.9 version
61 62 63 64 65 66 67 68 69 70 |
# File 'lib/resourceful/extensions.rb', line 61 def constantize #:nodoc: 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 |
#from_currency_to_f ⇒ Object
54 55 56 |
# File 'lib/resourceful/extensions.rb', line 54 def from_currency_to_f self.gsub(/[^0-9.-]/,'').to_f end |
#to_date ⇒ Object
42 43 44 |
# File 'lib/resourceful/extensions.rb', line 42 def to_date ::Date.civil(*::Date._parse(self, false).values_at(:year, :mon, :mday).map { |arg| arg || 0 }) rescue nil end |
#to_datetime ⇒ Object
36 37 38 |
# File 'lib/resourceful/extensions.rb', line 36 def to_datetime ::DateTime.civil(*::Date._parse(self, false).values_at(:year, :mon, :mday, :hour, :min, :sec).map { |arg| arg || 0 }) rescue nil end |
#to_resourceful_boolean ⇒ Object
48 49 50 |
# File 'lib/resourceful/extensions.rb', line 48 def to_resourceful_boolean self.nil? || self.empty? || self =~ /^(false|0)$/i ? false : true end |