Class: String
- Defined in:
- lib/syncwise_api/ext/string_encoding.rb,
lib/syncwise_api/ext/core_ext.rb
Overview
ripped from rails
Constant Summary collapse
- NON_WHITESPACE_REGEXP =
0x3000: fullwidth whitespace
%r![^\s#{[0x3000].pack("U")}]!
Instance Method Summary collapse
-
#blank? ⇒ Boolean
A string is blank if it’s empty or contains whitespaces only:.
-
#camelize(first_letter = :upper) ⇒ Object
(also: #camelcase)
By default,
camelize
converts strings to UpperCamelCase. - #dehumanize ⇒ Object
- #encoding_aware? ⇒ Boolean
- #underscore ⇒ Object
Instance Method Details
#blank? ⇒ Boolean
A string is blank if it’s empty or contains whitespaces only:
"".blank? # => true
" ".blank? # => true
" ".blank? # => true
" something here ".blank? # => false
124 125 126 127 128 129 130 131 |
# File 'lib/syncwise_api/ext/core_ext.rb', line 124 def blank? # 1.8 does not takes [:space:] properly if encoding_aware? self !~ /[^[:space:]]/ else self !~ NON_WHITESPACE_REGEXP end end |
#camelize(first_letter = :upper) ⇒ Object Also known as: camelcase
By default, camelize
converts strings to UpperCamelCase. If the argument to camelize is set to :lower
then camelize produces lowerCamelCase.
camelize
will also convert ‘/’ to ‘::’ which is useful for converting paths to namespaces.
"active_record".camelize # => "ActiveRecord"
"active_record".camelize(:lower) # => "activeRecord"
"active_record/errors".camelize # => "ActiveRecord::Errors"
"active_record/errors".camelize(:lower) # => "activeRecord::Errors"
151 152 153 154 155 156 |
# File 'lib/syncwise_api/ext/core_ext.rb', line 151 def camelize(first_letter = :upper) case first_letter when :upper then SyncwiseApi::Inflector.camelize(self, true) when :lower then SyncwiseApi::Inflector.camelize(self, false) end end |
#dehumanize ⇒ Object
133 134 135 |
# File 'lib/syncwise_api/ext/core_ext.rb', line 133 def dehumanize SyncwiseApi::Inflector.dehumanize(self) end |
#encoding_aware? ⇒ Boolean
4 5 6 |
# File 'lib/syncwise_api/ext/string_encoding.rb', line 4 def encoding_aware? true end |
#underscore ⇒ Object
137 138 139 |
# File 'lib/syncwise_api/ext/core_ext.rb', line 137 def underscore SyncwiseApi::Inflector.underscore(self) end |