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