useful_string_extensions 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ coverage
6
+ InstalledFiles
7
+ lib/bundler/man
8
+ pkg
9
+ rdoc
10
+ spec/reports
11
+ test/tmp
12
+ test/version_tmp
13
+ tmp
14
+
15
+ # YARD artifacts
16
+ .yardoc
17
+ _yardoc
18
+ doc/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in useful_string_extensions.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Andrey
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # UsefulStringExtensions
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'useful_string_extensions'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install useful_string_extensions
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,110 @@
1
+ # coding: utf-8
2
+ String.class_eval do
3
+ def string_from_file
4
+ data = ''
5
+ f = File.open(self, "r")
6
+ f.each_line do |line|
7
+ data += line
8
+ end
9
+ data
10
+ end
11
+
12
+ def replace_quotes
13
+ self == "" ? "" : self.gsub(""", '"')
14
+ end
15
+
16
+ def show?
17
+ self.blank? ? "Не указано" : self
18
+ end
19
+
20
+ def detect_encoding
21
+ CharDet.detect(text)['encoding'] rescue "utf-8"
22
+ end
23
+
24
+ def in_one_line
25
+ self.gsub("\n",'').gsub("\r",'').gsub("\t",'')
26
+ end
27
+
28
+ def get_id_from_url
29
+ self.split("-").last
30
+ end
31
+
32
+ def bstrip
33
+ self.lstrip.rstrip
34
+ end
35
+
36
+ def to_widgets_array
37
+ self.split(",").collect{|e| e.gsub("widget_",'').to_i}
38
+ end
39
+
40
+ def change_plus
41
+ self.gsub("+7", "8")
42
+ end
43
+
44
+ def to_keywords
45
+ self == '' ? '' : self.gsub(/\(\)\,\./, '').split(" ").collect {|e| Unicode.downcase(e)}.join(", ")
46
+ end
47
+
48
+ def to_simple_xhtml
49
+ self == '' ? '' : self.gsub("<br>", '<br />')
50
+ end
51
+
52
+ def remove_extension
53
+ File.basename(self, '.*')
54
+ end
55
+
56
+ def get_extension
57
+ File.extname(self)
58
+ end
59
+
60
+ def remove_promo
61
+ self.include?("::") ? self.split("::")[1] : self
62
+ end
63
+
64
+ def to_slug
65
+ Russian.translit(self).downcase.gsub(/[^a-z0-9]+/, '-').strip.chomp('-')
66
+
67
+ # другой вариант
68
+ #initial = Russian::translit(self.name).gsub(/[^A-Za-z0-9\s\-]/, "")[0,40].strip.gsub(/\s+/, "-").downcase
69
+ end
70
+
71
+ def to_search
72
+ self.blank? ? "" : self.sanitize_to_sphinx.split_stars
73
+ end
74
+
75
+ def remove_stars
76
+ self.blank? ? "" : self.gsub('*', '')
77
+ end
78
+
79
+ def sanitize_to_sphinx
80
+ Unicode.downcase(self).gsub(/[^a-zа-яёЁ0-9\*]/, ' ').split("[")[0].split(" ").compact.join(" ")#.strip
81
+ end
82
+
83
+ def split_stars
84
+ self.sanitize_to_sphinx.split(" ").collect {|w| "*#{w}*" if w.size > 2}.join(" ")
85
+ end
86
+
87
+ def end_stars
88
+ self.sanitize_to_sphinx.split(" ").collect {|w| "#{w}*" if w.size > 2}.join(" ")
89
+ end
90
+
91
+ def path_to_a
92
+ self.gsub(",", '').split(' ').compact
93
+ end
94
+
95
+ def capitalize
96
+ Unicode::capitalize(self)
97
+ end
98
+
99
+ def clearify
100
+ self.blank? ? "" : self.gsub('"', "'")
101
+ end
102
+
103
+ def is_valid_email?
104
+ !(self =~ CustomEmailValidator.email_regex).nil?
105
+ end
106
+
107
+ def to_page_slug
108
+ self.gsub(/^\//, '').gsub(".html", "")
109
+ end
110
+ end
@@ -0,0 +1,3 @@
1
+ module UsefulStringExtensions
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,2 @@
1
+ require "useful_string_extensions/version"
2
+ require "useful_string_extensions/string"
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/useful_string_extensions/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Andrey"]
6
+ gem.email = ["railscode@gmail.com"]
7
+ gem.description = "useful_string_extensions"
8
+ gem.summary = "useful_string_extensions"
9
+ gem.homepage = ""
10
+ gem.files = `git ls-files`.split($\)
11
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
12
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
13
+ gem.name = "useful_string_extensions"
14
+ gem.require_paths = ["lib"]
15
+ gem.version = UsefulStringExtensions::VERSION
16
+ gem.add_dependency "chardet", ">= 0.9.0"
17
+ gem.add_dependency "russian", ">= 0.6.0"
18
+ gem.add_dependency "unicode", ">= 0.4.2"
19
+ end
metadata ADDED
@@ -0,0 +1,102 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: useful_string_extensions
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Andrey
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-11-25 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: chardet
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 0.9.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 0.9.0
30
+ - !ruby/object:Gem::Dependency
31
+ name: russian
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: 0.6.0
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: 0.6.0
46
+ - !ruby/object:Gem::Dependency
47
+ name: unicode
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: 0.4.2
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: 0.4.2
62
+ description: useful_string_extensions
63
+ email:
64
+ - railscode@gmail.com
65
+ executables: []
66
+ extensions: []
67
+ extra_rdoc_files: []
68
+ files:
69
+ - .gitignore
70
+ - Gemfile
71
+ - LICENSE
72
+ - README.md
73
+ - Rakefile
74
+ - lib/useful_string_extensions.rb
75
+ - lib/useful_string_extensions/string.rb
76
+ - lib/useful_string_extensions/version.rb
77
+ - useful_string_extensions.gemspec
78
+ homepage: ''
79
+ licenses: []
80
+ post_install_message:
81
+ rdoc_options: []
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ none: false
86
+ requirements:
87
+ - - ! '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
+ none: false
92
+ requirements:
93
+ - - ! '>='
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ requirements: []
97
+ rubyforge_project:
98
+ rubygems_version: 1.8.19
99
+ signing_key:
100
+ specification_version: 3
101
+ summary: useful_string_extensions
102
+ test_files: []