Class: String
Constant Summary collapse
- KEYBOARDS =
lucene.apache.org/core/old_versioned_docs/versions/2_9_1/queryparsersyntax.html LUCENE_ESCAPE_REGEX = /(+|-|&&||||!|(|)|{|}|[|]|‘|“|~|?|:|\|/)/ LUCENE_ESCAPE_REGEX = /(+|-|&&||||!|(|)|{|}|[|]|`|”|~|?|:|\|s)/
{ en: 'qwertyuiop[]asdfghjkl;\'zxcvbnm,./', ru: 'йцукенгшщзхъфывапролджэячсмитьбю/' }
- LUCENE_ESCAPE_REGEX =
/(\+|-|&&|\|\||!|\(|\)|{|}|\[|\]|\^|"|~|\*|\?|:|\\|\/)/
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
- #mb_downcase ⇒ Object
- #mb_upcase ⇒ 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
19 20 21 |
# File 'lib/ab_admin/core_ext/string.rb', line 19 def capitalize_first self.mb_chars[0].capitalize + self.mb_chars[1..-1] end |
#clean_text ⇒ Object
78 79 80 81 |
# File 'lib/ab_admin/core_ext/string.rb', line 78 def clean_text coder = HTMLEntities.new coder.decode(self.no_html) end |
#count_words ⇒ Object
64 65 66 |
# File 'lib/ab_admin/core_ext/string.rb', line 64 def count_words clean_text.scan(/(\p{Alnum}+([-'.]\p{Alnum}+)*)/u).size end |
#is_int? ⇒ Boolean
23 24 25 |
# File 'lib/ab_admin/core_ext/string.rb', line 23 def is_int? self =~ /^[-+]?[0-9]+$/ end |
#is_number? ⇒ Boolean
27 28 29 |
# File 'lib/ab_admin/core_ext/string.rb', line 27 def is_number? self =~ /^[-+]?[0-9]+(\.[0-9]+)?$/ end |
#lucene_escape ⇒ Object
14 15 16 |
# File 'lib/ab_admin/core_ext/string.rb', line 14 def lucene_escape self.gsub(LUCENE_ESCAPE_REGEX, "\\\\\\1") end |
#mb_downcase ⇒ Object
87 88 89 |
# File 'lib/ab_admin/core_ext/string.rb', line 87 def mb_downcase mb_chars.downcase.to_s end |
#mb_upcase ⇒ Object
83 84 85 |
# File 'lib/ab_admin/core_ext/string.rb', line 83 def mb_upcase mb_chars.upcase.to_s end |
#no_html ⇒ Object
39 40 41 42 43 44 45 46 |
# File 'lib/ab_admin/core_ext/string.rb', line 39 def no_html str = self.dup str.gsub!(/<br\/?>/, ' ') str.gsub!(/<\/?[^>]*>/, '') str.strip! str.gsub!(' ', ' ') str end |
#to_utc ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/ab_admin/core_ext/string.rb', line 31 def to_utc begin Time.zone.parse(self).utc rescue Time.now.utc end end |
#tr_lang(from = nil, to = nil) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/ab_admin/core_ext/string.rb', line 48 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 |