titleize_br 1.0.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: ff00bc73a8ff03715df6c49b937bc9471089fa0e8a8a335ed21a399461c336c4
4
+ data.tar.gz: 00c77b67bf913d6969844401400123253033fd6545324b0ef72f482047843dc6
5
+ SHA512:
6
+ metadata.gz: 656cb7b5b352674c0e94a5c7561b6661b7a84e2d5dec7d99db377bf4309578952b8f4161b1d20cf163ca092e9fad8de912a5f7d8797987ec00ea728a8faeed92
7
+ data.tar.gz: 2f61ad4cb369bb0c6933617ababa1dbea59d2c07bd39991b5d69ae055c12f4ef7a1540feb111eec8ba704ed8c5b40ae96d74f523fccf8be36dd2ae316ce64eee
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,20 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.5
3
+
4
+ Style/StringLiterals:
5
+ Enabled: true
6
+ EnforcedStyle: single_quotes
7
+
8
+ Style/StringLiteralsInInterpolation:
9
+ Enabled: true
10
+ EnforcedStyle: double_quotes
11
+
12
+ Layout/LineLength:
13
+ Max: 120
14
+
15
+ Style/Documentation:
16
+ Enabled: false
17
+
18
+ Metrics/BlockLength:
19
+ Exclude:
20
+ - spec/*
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ titleize_br
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [1.0.0] - 2023-04-30
4
+
5
+ - Initial release
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in titleize_br.gemspec
6
+ gemspec
7
+
8
+ gem 'rake', '~> 13.0'
9
+
10
+ gem 'rspec', '~> 3.0'
11
+
12
+ gem 'rubocop', '~> 1.21'
data/Gemfile.lock ADDED
@@ -0,0 +1,69 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ titleize_br (1.0.0)
5
+ activesupport (> 4)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ activesupport (6.1.7.3)
11
+ concurrent-ruby (~> 1.0, >= 1.0.2)
12
+ i18n (>= 1.6, < 2)
13
+ minitest (>= 5.1)
14
+ tzinfo (~> 2.0)
15
+ zeitwerk (~> 2.3)
16
+ ast (2.4.2)
17
+ concurrent-ruby (1.2.2)
18
+ diff-lcs (1.5.0)
19
+ i18n (1.13.0)
20
+ concurrent-ruby (~> 1.0)
21
+ minitest (5.15.0)
22
+ parallel (1.23.0)
23
+ parser (3.2.2.1)
24
+ ast (~> 2.4.1)
25
+ rainbow (3.1.1)
26
+ rake (13.0.6)
27
+ regexp_parser (2.8.0)
28
+ rexml (3.2.5)
29
+ rspec (3.12.0)
30
+ rspec-core (~> 3.12.0)
31
+ rspec-expectations (~> 3.12.0)
32
+ rspec-mocks (~> 3.12.0)
33
+ rspec-core (3.12.2)
34
+ rspec-support (~> 3.12.0)
35
+ rspec-expectations (3.12.3)
36
+ diff-lcs (>= 1.2.0, < 2.0)
37
+ rspec-support (~> 3.12.0)
38
+ rspec-mocks (3.12.5)
39
+ diff-lcs (>= 1.2.0, < 2.0)
40
+ rspec-support (~> 3.12.0)
41
+ rspec-support (3.12.0)
42
+ rubocop (1.28.2)
43
+ parallel (~> 1.10)
44
+ parser (>= 3.1.0.0)
45
+ rainbow (>= 2.2.2, < 4.0)
46
+ regexp_parser (>= 1.8, < 3.0)
47
+ rexml
48
+ rubocop-ast (>= 1.17.0, < 2.0)
49
+ ruby-progressbar (~> 1.7)
50
+ unicode-display_width (>= 1.4.0, < 3.0)
51
+ rubocop-ast (1.17.0)
52
+ parser (>= 3.1.1.0)
53
+ ruby-progressbar (1.13.0)
54
+ tzinfo (2.0.6)
55
+ concurrent-ruby (~> 1.0)
56
+ unicode-display_width (2.4.2)
57
+ zeitwerk (2.6.8)
58
+
59
+ PLATFORMS
60
+ ruby
61
+
62
+ DEPENDENCIES
63
+ rake (~> 13.0)
64
+ rspec (~> 3.0)
65
+ rubocop (~> 1.21)
66
+ titleize_br!
67
+
68
+ BUNDLED WITH
69
+ 1.17.3
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Gabriel Rodríguez
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 all
13
+ 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 THE
21
+ SOFTWARE.
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2023 Gabriel Rodriguez
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,44 @@
1
+ # TitleizeBr
2
+
3
+ This gem is gives brazilians an easy way to titleize strings with our own grammar rules from ABNT.
4
+
5
+ ```ruby
6
+ 'o teste de titleize'.titleize
7
+ => "O Teste De Titleize"
8
+ 'o teste de titleize'.titleize_br
9
+ => "O Teste de Titleize"
10
+ ```
11
+
12
+ - First character or word is always capitalized
13
+ - Connectives (pronouns and articles) are not capitalized unless they appear first
14
+
15
+ Please open an issue or pull request if you find a word that is not being treated correctly
16
+
17
+ ## Installation
18
+
19
+ Install the gem and add to the application's Gemfile by executing:
20
+
21
+ $ bundle add titleize_br
22
+
23
+ If bundler is not being used to manage dependencies, install the gem by executing:
24
+
25
+ $ gem install titleize_br
26
+
27
+ ## Usage
28
+
29
+ `'string'.titleize_br`
30
+
31
+ ## Development
32
+
33
+ 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.
34
+
35
+ 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 the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
36
+
37
+ ## Contributing
38
+
39
+ Bug reports and pull requests are welcome on GitHub at https://github.com/gabrielrdrguez/titleize_br.
40
+ Please use imperative commit messages: https://cbea.ms/git-commit/#imperative
41
+
42
+ ## License
43
+
44
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require 'rubocop/rake_task'
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ class String
4
+ def titleize_br
5
+ TitleizeBr.titleize(self)
6
+ end
7
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TitleizeBr
4
+ VERSION = '1.0.0'
5
+ end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'titleize_br/version'
4
+ require 'active_support/core_ext/string/inflections'
5
+ require 'core_ext/string'
6
+
7
+ module TitleizeBr
8
+ class Error < StandardError; end
9
+ CONNECTIVES = %w[a ao aos as com da das de do dos e em na nas no nos o os ou para pela pelas pelo pelos pra pras pro
10
+ pros um uma à às á é].freeze
11
+ class << self
12
+ def titleize(string)
13
+ parts = string.titleize.split(' ').map do |word|
14
+ infer_case_of_word(word)
15
+ end
16
+
17
+ parts.first.capitalize! if connective?(parts.first)
18
+ parts.join(' ')
19
+ end
20
+
21
+ private
22
+
23
+ def connective?(string)
24
+ regex = /^(#{CONNECTIVES.join('|')})$/i
25
+ string.strip.match?(regex)
26
+ end
27
+
28
+ def roman_numeral?(word)
29
+ word.strip.match(/^M{0,3}(CM|CD|D?C{0,3})(XC|XL|L?X{0,3})(IX|IV|V?I{0,3})$/i)
30
+ end
31
+
32
+ def infer_case_of_word(word)
33
+ word.downcase! if connective?(word)
34
+ word.upcase! if roman_numeral?(word)
35
+ word
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,4 @@
1
+ module TitleizeBr
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/titleize_br/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'titleize_br'
7
+ spec.version = TitleizeBr::VERSION
8
+ spec.authors = ['Gabriel Rodriguez']
9
+ spec.email = ['gabriel.rdrguez@gmail.com']
10
+
11
+ spec.summary = 'Rails String#titleize but with brazilian ABNT rules.'
12
+ spec.homepage = 'https://github.com/gabrielrdrguez/titleize_br'
13
+ spec.license = 'MIT'
14
+ spec.required_ruby_version = '>= 2.5.0'
15
+
16
+ spec.metadata['homepage_uri'] = spec.homepage
17
+ spec.metadata['source_code_uri'] = 'https://github.com/gabrielrdrguez/titleize_br'
18
+ spec.metadata['changelog_uri'] = 'https://github.com/gabrielrdrguez/titleize_br/blob/main/CHANGELOG.md.'
19
+
20
+ # Specify which files should be added to the gem when it is released.
21
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
22
+ spec.files = Dir.chdir(__dir__) do
23
+ `git ls-files -z`.split("\x0").reject do |f|
24
+ (File.expand_path(f) == __FILE__) || f.start_with?(*%w[bin/ test/ spec/ features/ .git .circleci appveyor])
25
+ end
26
+ end
27
+ spec.bindir = 'exe'
28
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
29
+ spec.require_paths = ['lib']
30
+
31
+ # Uncomment to register a new dependency of your gem
32
+ spec.add_dependency 'activesupport', '> 4'
33
+
34
+ # For more information and examples about making a new gem, check out our
35
+ # guide at: https://bundler.io/guides/creating_gem.html
36
+ end
metadata ADDED
@@ -0,0 +1,75 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: titleize_br
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Gabriel Rodriguez
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2023-04-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">"
18
+ - !ruby/object:Gem::Version
19
+ version: '4'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">"
25
+ - !ruby/object:Gem::Version
26
+ version: '4'
27
+ description:
28
+ email:
29
+ - gabriel.rdrguez@gmail.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ".rspec"
35
+ - ".rubocop.yml"
36
+ - ".ruby-gemset"
37
+ - CHANGELOG.md
38
+ - Gemfile
39
+ - Gemfile.lock
40
+ - LICENSE
41
+ - LICENSE.txt
42
+ - README.md
43
+ - Rakefile
44
+ - lib/core_ext/string.rb
45
+ - lib/titleize_br.rb
46
+ - lib/titleize_br/version.rb
47
+ - sig/titleize_br.rbs
48
+ - titleize_br.gemspec
49
+ homepage: https://github.com/gabrielrdrguez/titleize_br
50
+ licenses:
51
+ - MIT
52
+ metadata:
53
+ homepage_uri: https://github.com/gabrielrdrguez/titleize_br
54
+ source_code_uri: https://github.com/gabrielrdrguez/titleize_br
55
+ changelog_uri: https://github.com/gabrielrdrguez/titleize_br/blob/main/CHANGELOG.md.
56
+ post_install_message:
57
+ rdoc_options: []
58
+ require_paths:
59
+ - lib
60
+ required_ruby_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: 2.5.0
65
+ required_rubygems_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ requirements: []
71
+ rubygems_version: 3.0.8
72
+ signing_key:
73
+ specification_version: 4
74
+ summary: Rails String#titleize but with brazilian ABNT rules.
75
+ test_files: []