sanetitle 0.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.coveralls.yml +1 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +13 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +104 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/sanetitle.rb +66 -0
- data/lib/sanetitle/version.rb +3 -0
- data/sanetitle.gemspec +27 -0
- metadata +105 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 42359086950b2c27ccdf088053a75afe7cc9d6b3
|
4
|
+
data.tar.gz: 2d9566449da08027f478e1324a225451c2ef937a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c37935cb4d618fe7c17a33a74aed5befdc35b0c0deb22dc61a6a42f2d18587b06641661d087f45e209f19e4b51f5c23f4fa7ea246ade13ad4d67bd88c5ff88e0
|
7
|
+
data.tar.gz: 31069558a9744849365ea6db59528d723a4de22697b7bf2887b31cbab355787eedb63e3e3b05da9193a82bc018e10e0a88271ac5d917fd0c32c15e253aa3a6f4
|
data/.coveralls.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
repo_token: 4rcQKlhInCbdu5FcMdQ5zF9FqsUT9Cdr0
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
sanetitle
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby-2.3.3
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Edvaldo Silva de Almeida Júnior
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
# SaneTitle
|
2
|
+
|
3
|
+
[](https://badge.fury.io/gh/MIT-Licensed-gems%2Fsanetitle)
|
4
|
+
[](https://travis-ci.org/EdDeAlmeidaJr/sanetitle.svg?branch=master)
|
5
|
+
[](https://codeclimate.com/repos/56b8b4bb67fabe0fbc00274f/feed)
|
6
|
+
[](https://codeclimate.com/repos/56b8b4bb67fabe0fbc00274f/feed)
|
7
|
+
|
8
|
+
|
9
|
+
This gem generates a sane hyfen-separated text to serve as URL address to a page, based on a given string. It is ideal to generate a URL based on a title of a blog post or article, thus the name of the gem.
|
10
|
+
|
11
|
+
## Installation
|
12
|
+
|
13
|
+
Add this line to your application's Gemfile:
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
gem 'sanetitle'
|
17
|
+
```
|
18
|
+
|
19
|
+
And then execute:
|
20
|
+
|
21
|
+
```bash
|
22
|
+
$ bundle
|
23
|
+
```
|
24
|
+
|
25
|
+
Or install it yourself as:
|
26
|
+
|
27
|
+
```bash
|
28
|
+
$ gem install sanetitle
|
29
|
+
```
|
30
|
+
|
31
|
+
## Usage
|
32
|
+
|
33
|
+
The usage is quite simple.
|
34
|
+
|
35
|
+
Just create a SaneTitle::Sanitize object, passing the string you want to make sane, like:
|
36
|
+
|
37
|
+
```ruby
|
38
|
+
obj = SaneTitle::Sanifier.new("Este é um exemplo de string que será corrigida no curso da programação")
|
39
|
+
```
|
40
|
+
|
41
|
+
and then store the sane string in a variable with
|
42
|
+
|
43
|
+
```ruby
|
44
|
+
sane_title = obj.result
|
45
|
+
```
|
46
|
+
|
47
|
+
In this particular case, the variable sane_title shall contain "este-e-um-exemplo-de-string-que-sera-corrigida-no-curso-da-programacao".
|
48
|
+
|
49
|
+
From release 0.3.0 on, one may also call
|
50
|
+
|
51
|
+
```ruby
|
52
|
+
sane_title = obj.result_imp(<limit>,<html>,<tstamp>)
|
53
|
+
```
|
54
|
+
|
55
|
+
where:
|
56
|
+
|
57
|
+
<limit> is an integer value used to require that the size of the result string is limited to this size, and
|
58
|
+
<html> is a boolean value to require (true) or not (false) that the extension .html is appended to the result.
|
59
|
+
<tstamp> is a boolean value to indicating if the result string must be prepended with a timestamp in the format "yyyy-mm-dd-hh-mm-ss-"
|
60
|
+
|
61
|
+
Note two important things:
|
62
|
+
|
63
|
+
1) If you use
|
64
|
+
|
65
|
+
```ruby
|
66
|
+
sane_title = obj.result_imp(20,true)
|
67
|
+
```
|
68
|
+
|
69
|
+
the result string shall have, in fact, a lenght of 25. 20 from the limit you asked, plus five, which is the size of the extension .html. If you want a total of 20 positions you should say
|
70
|
+
|
71
|
+
```ruby
|
72
|
+
sane_title = obj.result_imp(15,true)
|
73
|
+
```
|
74
|
+
|
75
|
+
## Important advice
|
76
|
+
|
77
|
+
This gem makes no assumption about filesystems. Then, if you intend to use the filename obtained here as a name of a file to be written, **please take care of duplicate names before writing**. We won't accept any responsability on data loss.
|
78
|
+
|
79
|
+
## Development
|
80
|
+
|
81
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
82
|
+
|
83
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
84
|
+
|
85
|
+
## Donating
|
86
|
+
|
87
|
+
Cosider supporting my work [donating](https://gratipay.com/~EdDeAlmeidaJr/) some money. This will help me to create more and more useful gems to enrich Ruby's ecosystem.
|
88
|
+
|
89
|
+
## Contributing
|
90
|
+
|
91
|
+
If you want to contribute to this project, your help is welcome, for sure. But please, take some note before you start, so you won't tell me you didn't knew these things beforehand:
|
92
|
+
|
93
|
+
01) We are here to develop some software, not to discuss politics, race, religion, gender or any other issue the 'politically correct' people like to raise to disguise their inability to make things happen.
|
94
|
+
|
95
|
+
02) Opinions given by any developer outside the scope of this project are not our business. We don't care about what what you think, as long as you do NOT bring your opinions to this development space.
|
96
|
+
|
97
|
+
03) You may not raise issues about things not related to this project. This includes issues related to other developer's opinions given outside here.
|
98
|
+
|
99
|
+
04) Just to summarize all things said before: **Keep your personal stuff far away from this project and discuss only the project in its context**.
|
100
|
+
|
101
|
+
## License
|
102
|
+
|
103
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
104
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "sanetitle"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/lib/sanetitle.rb
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
require "sanetitle/version"
|
2
|
+
|
3
|
+
module SaneTitle
|
4
|
+
|
5
|
+
class Sanifier
|
6
|
+
|
7
|
+
def initialize(title)
|
8
|
+
raise ArgumentError.new('Invalid string.') unless (is_string?(title) and empty_string?(title))
|
9
|
+
step1 = title
|
10
|
+
step2 = to_lower(step1)
|
11
|
+
step3 = remove_special_chars(step2)
|
12
|
+
step4 = spaces_to_underlines(step3)
|
13
|
+
@@title_str = step4
|
14
|
+
end
|
15
|
+
|
16
|
+
def to_lower(str)
|
17
|
+
str.downcase
|
18
|
+
end
|
19
|
+
|
20
|
+
def spaces_to_underlines(str)
|
21
|
+
str.gsub(/\ /,"-")
|
22
|
+
end
|
23
|
+
|
24
|
+
def remove_special_chars(str)
|
25
|
+
s1 = str.gsub(/[á|à|ã|ä|â]/,"a")
|
26
|
+
s1 = s1.gsub(/[é|è|ẽ|ë|ê]/,"e")
|
27
|
+
s1 = s1.gsub(/[í|ì|ĩ|ï|î]/,"i")
|
28
|
+
s1 = s1.gsub(/[ó|ò|õ|ö|ô]/,"o")
|
29
|
+
s1 = s1.gsub(/[ú|ù|ũ|ü|û]/,"u")
|
30
|
+
s1 = s1.gsub(/[ñ]/,"n")
|
31
|
+
s1 = s1.gsub(/[ç]/,"c")
|
32
|
+
s1 = s1.gsub(/[\+|\=|\_|\-|\(|\)|\*|\%|\&|\$|\#|\@|\!|\?|\/|\:|\;|\.|\,|\>|\<]/,"")
|
33
|
+
s1.gsub(/\ \ /," ")
|
34
|
+
end
|
35
|
+
|
36
|
+
def result
|
37
|
+
@@title_str
|
38
|
+
end
|
39
|
+
|
40
|
+
def result_imp(lim,html,tstamp = false)
|
41
|
+
resimp = result
|
42
|
+
resimp = resimp[0,lim]
|
43
|
+
if (html) then
|
44
|
+
resimp = resimp + '.html'
|
45
|
+
end
|
46
|
+
if (tstamp) then
|
47
|
+
dt = DateTime.now
|
48
|
+
yyyy = dt.year.to_s
|
49
|
+
mm = (dt.month < 10) ? '0' + dt.month.to_s : dt.month.to_s
|
50
|
+
dd = (dt.day < 10) ? '0' + dt.day.to_s : dt.day.to_s
|
51
|
+
resimp = "#{yyyy}-#{mm}-#{dd}-#{resimp}"
|
52
|
+
end
|
53
|
+
resimp
|
54
|
+
end
|
55
|
+
|
56
|
+
def is_string?(title)
|
57
|
+
title.is_a? String
|
58
|
+
end
|
59
|
+
|
60
|
+
def empty_string?(title)
|
61
|
+
title.length > 0
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
data/sanetitle.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'sanetitle/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "sanetitle"
|
8
|
+
spec.version = SaneTitle::VERSION
|
9
|
+
spec.authors = ["Edvaldo Silva de Almeida Júnior"]
|
10
|
+
spec.email = ["edvaldoajunior@gmail.com"]
|
11
|
+
|
12
|
+
spec.required_ruby_version = '>= 2.2.0'
|
13
|
+
|
14
|
+
spec.summary = "Generates a sane string which may be used as a URL, based on a sentence."
|
15
|
+
spec.description = "This gem generates a sane hyfen-separated text to serve as URL address to a page, based on a given string. It is ideal to generate a URL based on a title of a blog post or article, thus the name of the gem."
|
16
|
+
spec.homepage = "https://github.com/EdDeAlmeidaJr/sanetitle"
|
17
|
+
spec.license = "MIT"
|
18
|
+
|
19
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
20
|
+
spec.bindir = "bin"
|
21
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
22
|
+
spec.require_paths = ["lib"]
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.13"
|
25
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
26
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sanetitle
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.3.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Edvaldo Silva de Almeida Júnior
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-12-22 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.13'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.13'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
description: This gem generates a sane hyfen-separated text to serve as URL address
|
56
|
+
to a page, based on a given string. It is ideal to generate a URL based on a title
|
57
|
+
of a blog post or article, thus the name of the gem.
|
58
|
+
email:
|
59
|
+
- edvaldoajunior@gmail.com
|
60
|
+
executables:
|
61
|
+
- console
|
62
|
+
- setup
|
63
|
+
extensions: []
|
64
|
+
extra_rdoc_files: []
|
65
|
+
files:
|
66
|
+
- ".coveralls.yml"
|
67
|
+
- ".gitignore"
|
68
|
+
- ".rspec"
|
69
|
+
- ".ruby-gemset"
|
70
|
+
- ".ruby-version"
|
71
|
+
- ".travis.yml"
|
72
|
+
- Gemfile
|
73
|
+
- LICENSE.txt
|
74
|
+
- README.md
|
75
|
+
- Rakefile
|
76
|
+
- bin/console
|
77
|
+
- bin/setup
|
78
|
+
- lib/sanetitle.rb
|
79
|
+
- lib/sanetitle/version.rb
|
80
|
+
- sanetitle.gemspec
|
81
|
+
homepage: https://github.com/EdDeAlmeidaJr/sanetitle
|
82
|
+
licenses:
|
83
|
+
- MIT
|
84
|
+
metadata: {}
|
85
|
+
post_install_message:
|
86
|
+
rdoc_options: []
|
87
|
+
require_paths:
|
88
|
+
- lib
|
89
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: 2.2.0
|
94
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
96
|
+
- - ">="
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
requirements: []
|
100
|
+
rubyforge_project:
|
101
|
+
rubygems_version: 2.5.2
|
102
|
+
signing_key:
|
103
|
+
specification_version: 4
|
104
|
+
summary: Generates a sane string which may be used as a URL, based on a sentence.
|
105
|
+
test_files: []
|