Class: String
- Defined in:
- lib/ab_admin/core_ext/string.rb,
lib/ab_admin/core_ext/string.rb
Constant Summary collapse
- LUCENE_ESCAPE_REGEX =
LUCENE_ESCAPE_REGEX = /(+|-|&&||||!|(|)|{|}|[|]|‘|“|~|?|:|\)/
/(\+|-|&&|\|\||!|\(|\)|{|}|\[|\]|`|"|~|\?|:|\\|\s)/
Class Method Summary collapse
Instance Method Summary collapse
- #capitalize_first ⇒ Object
- #clean_text ⇒ Object
- #is_int? ⇒ Boolean
- #is_number? ⇒ Boolean
- #lucene_escape ⇒ Object
- #no_html ⇒ Object
- #to_utc ⇒ Object
- #tr_lang(from = nil, to = nil) ⇒ Object
- #words_count ⇒ Object
Class Method Details
Instance Method Details
#capitalize_first ⇒ Object
10 11 12 |
# File 'lib/ab_admin/core_ext/string.rb', line 10 def capitalize_first self.mb_chars[0].capitalize + self.mb_chars[1..-1] end |
#clean_text ⇒ Object
73 74 75 76 |
# File 'lib/ab_admin/core_ext/string.rb', line 73 def clean_text coder = HTMLEntities.new coder.decode(self.no_html) end |
#is_int? ⇒ Boolean
14 15 16 |
# File 'lib/ab_admin/core_ext/string.rb', line 14 def is_int? self =~ /^[-+]?[0-9]*$/ end |
#is_number? ⇒ Boolean
18 19 20 |
# File 'lib/ab_admin/core_ext/string.rb', line 18 def is_number? true if Float(self) rescue false end |
#lucene_escape ⇒ Object
6 7 8 |
# File 'lib/ab_admin/core_ext/string.rb', line 6 def lucene_escape self.gsub(LUCENE_ESCAPE_REGEX, "\\\\\\1") end |
#no_html ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/ab_admin/core_ext/string.rb', line 30 def no_html str = self.dup str.gsub!(/<\/?[^>]*>/, '') str.strip! str.gsub!(' ', ' ') str end |
#to_utc ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/ab_admin/core_ext/string.rb', line 22 def to_utc begin Time.zone.parse(self).utc rescue Time.now.utc end end |
#tr_lang(from = nil, to = nil) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/ab_admin/core_ext/string.rb', line 38 def tr_lang(from=nil, to=nil) return '' if self.blank? keyboard = {} keyboard[:en] = %{qwertyuiop[]asdfghjkl;'zxcvbnm,./} keyboard[:ru] = %{йцукенгшщзхъфывапролджэячсмитьбю/} unless from || to if keyboard[:en].index(self[0]) from, to = :en, :ru elsif keyboard[:ru].index(self[0]) from, to = :ru, :en else from, to = :en, :ru end end self.tr(keyboard[from], keyboard[to]) end |