Class: String
- Defined in:
- lib/acts_as_unvlogable/string_base.rb,
lib/acts_as_unvlogable/string_extend.rb
Overview
This removes the activesupport dependency
Instance Method Summary collapse
- #camelize(first_letter_in_uppercase = true) ⇒ Object
- #constantize ⇒ Object
- #humanize ⇒ Object
- #query_param(param_name) ⇒ Object
Instance Method Details
#camelize(first_letter_in_uppercase = true) ⇒ Object
4 5 6 7 8 9 10 |
# File 'lib/acts_as_unvlogable/string_base.rb', line 4 def camelize(first_letter_in_uppercase = true) if first_letter_in_uppercase self.to_s.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase } else self.first + camelize(self)[1..-1] end end |
#constantize ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'lib/acts_as_unvlogable/string_base.rb', line 12 def constantize camel_cased_word = self unless /\A(?:::)?([A-Z]\w*(?:::[A-Z]\w*)*)\z/ =~ camel_cased_word raise NameError, "#{camel_cased_word.inspect} is not a valid constant name!" end Object.module_eval("::#{$1}", __FILE__, __LINE__) end |
#humanize ⇒ Object
21 22 23 |
# File 'lib/acts_as_unvlogable/string_base.rb', line 21 def humanize self.to_s.gsub(/_id$/, "").gsub(/_/, " ").capitalize end |
#query_param(param_name) ⇒ Object
3 4 5 6 7 |
# File 'lib/acts_as_unvlogable/string_extend.rb', line 3 def query_param(param_name) raise ArgumentError.new("param name can't be nil") if param_name.blank? uri = URI.parse(self) (CGI::parse(uri.query)[param_name].first.to_s if uri.query) || nil end |