pascoale 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bfd6cfb79a1e6ef372e86ccd6eba1e414f256ac7
4
- data.tar.gz: 85e7e768620a374cb72588e54de90e6166cb2f4f
3
+ metadata.gz: c8ce764aef7a0c803c94a6a5ef4d0387b392250b
4
+ data.tar.gz: 2f8e9bb20376854c7375ff4217d32063b45b74d9
5
5
  SHA512:
6
- metadata.gz: b3f0f665e8daab808873ca392de860ddbd1da1e7e361466bee69aed3728032b73aa926720056bc01e416eee12cc4270de3df036b45f2f9801f839d0c38aea705
7
- data.tar.gz: 69e36730f1c1f809f8e5d4117f044e5948a2ab89065dae57bb69160117d499181ded61ba873d2a6640953018155c03671964dfd1e9cead0c9f9b65e53e385896
6
+ metadata.gz: cc8f197ff4c99da3cfd5aba70ed1bc32d87e88cc33da29ab2966af72bf3964ea7a5d9ea099a158da6a29e509ce7215d9a0a140403a9bff91ecbae658d372ca64
7
+ data.tar.gz: 379a5a131cccf7ab26faaf6e7948e996732290cb46c30e451979b0e9a4c8d7afd1480b4f9bbd8483fcb2d5e72419a1cb2f4c0d7fe48e6d10a39fa64f91c71b98
data/Guardfile CHANGED
@@ -1,4 +1,4 @@
1
- guard :rspec do
1
+ guard :rspec, all_on_start: true, keep: true, all_after_pass: true, cmd: 'bundle exec rspec', run_all: { cmd: 'bundle exec rspec -f progress' } do
2
2
  watch(%r{^spec/.+_spec\.rb$})
3
3
  watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
4
4
  watch('spec/spec_helper.rb') { "spec" }
data/lib/pascoale.rb CHANGED
@@ -8,3 +8,4 @@ require 'pascoale/version'
8
8
  require 'pascoale/constants'
9
9
  require 'pascoale/edits'
10
10
  require 'pascoale/syllable_separator'
11
+ require 'pascoale/formatter'
@@ -0,0 +1,54 @@
1
+ module Pascoale
2
+ class Formatter
3
+ EXCEPTIONS = %(a o e da do de na no em as os das dos nas nos à com sem)
4
+
5
+ def initialize(text)
6
+ @text = text
7
+ end
8
+
9
+ def as_title
10
+ def title_word(a_word)
11
+ if EXCEPTIONS.include?(a_word.downcase)
12
+ a_word.downcase
13
+ else
14
+ a_word.capitalize
15
+ end
16
+ end
17
+
18
+ words = @text.split(/\s+/).map { |word| Formatter.new(word) }
19
+ first = words.first
20
+ first = first.upcase? ? first : first.capitalize
21
+ rest = words[1..-1].map { |word| word.upcase? ? word : title_word(word) }
22
+ ([first] + rest).join(' ')
23
+ end
24
+
25
+ def upcase?
26
+ self.upcase == @text
27
+ end
28
+
29
+ def downcase?
30
+ self.downcase == @text
31
+ end
32
+
33
+ def capitalize?
34
+ self.capitalize == @text
35
+ end
36
+
37
+ def upcase
38
+ @text.upcase.tr('áéíóúâêôãõçü', 'ÁÉÍÓÚÂÊÔÃÕÇÜ')
39
+ end
40
+
41
+ def downcase
42
+ @text.downcase.tr('ÁÉÍÓÚÂÊÔÃÕÇÜ', 'áéíóúâêôãõçü')
43
+ end
44
+
45
+ def capitalize
46
+ Formatter.new(@text[0..0]).upcase +
47
+ Formatter.new(@text[1..-1]).downcase
48
+ end
49
+
50
+ def to_s
51
+ @text
52
+ end
53
+ end
54
+ end
@@ -1,3 +1,3 @@
1
1
  module Pascoale
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
data/pascoale.gemspec CHANGED
@@ -17,8 +17,8 @@ Gem::Specification.new do |spec|
17
17
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
18
  spec.require_paths = ['lib']
19
19
 
20
- spec.add_development_dependency 'bundler', ['~>1.5', '>=1.5.1']
20
+ spec.add_development_dependency 'bundler'
21
21
  spec.add_development_dependency 'rake'
22
- spec.add_development_dependency 'rspec', '~> 3.0.beta'
23
- spec.add_development_dependency 'guard-rspec'
22
+ spec.add_development_dependency 'rspec', '~> 3'
23
+ spec.add_development_dependency 'guard-rspec', '~> 4'
24
24
  end
@@ -0,0 +1,46 @@
1
+ require 'spec_helper'
2
+
3
+ describe Pascoale::Formatter do
4
+ describe '#as_title' do
5
+ it 'formats simple text' do
6
+ formatter = Pascoale::Formatter.new('teste')
7
+ expect(formatter.as_title).to eq 'Teste'
8
+ end
9
+
10
+ it 'formats simple text with accent' do
11
+ formatter = Pascoale::Formatter.new('épico')
12
+ expect(formatter.as_title).to eq 'Épico'
13
+ end
14
+
15
+ it 'formats multiple words' do
16
+ formatter = Pascoale::Formatter.new('joão alves ferreira')
17
+ expect(formatter.as_title).to eq 'João Alves Ferreira'
18
+ end
19
+
20
+ it 'formats prepositions and connect words as exceptions' do
21
+ formatter = Pascoale::Formatter.new('josé da silva e santos dos anjos')
22
+ expect(formatter.as_title).to eq 'José da Silva e Santos dos Anjos'
23
+ end
24
+
25
+ it 'formats first words always as capitalized' do
26
+ formatter = Pascoale::Formatter.new('da vida e das coisas')
27
+ expect(formatter.as_title).to eq 'Da Vida e das Coisas'
28
+ end
29
+
30
+ it 'formats acronyms' do
31
+ formatter = Pascoale::Formatter.new('a ONU não gosta de violência')
32
+ expect(formatter.as_title).to eq 'A ONU Não Gosta de Violência'
33
+
34
+ formatter = Pascoale::Formatter.new('IRQ é algo ultrapassado!')
35
+ expect(formatter.as_title).to eq 'IRQ É Algo Ultrapassado!'
36
+ end
37
+ end
38
+
39
+ describe '#upcase'
40
+ describe '#downcase'
41
+ describe '#capitalize'
42
+ describe '#upcase?'
43
+ describe '#dowcase?'
44
+ describe '#capitalize?'
45
+ describe '#to_s'
46
+ end
metadata CHANGED
@@ -1,35 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pascoale
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ronie Uliana
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-12 00:00:00.000000000 Z
11
+ date: 2014-08-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: '1.5'
20
17
  - - ">="
21
18
  - !ruby/object:Gem::Version
22
- version: 1.5.1
19
+ version: '0'
23
20
  type: :development
24
21
  prerelease: false
25
22
  version_requirements: !ruby/object:Gem::Requirement
26
23
  requirements:
27
- - - "~>"
28
- - !ruby/object:Gem::Version
29
- version: '1.5'
30
24
  - - ">="
31
25
  - !ruby/object:Gem::Version
32
- version: 1.5.1
26
+ version: '0'
33
27
  - !ruby/object:Gem::Dependency
34
28
  name: rake
35
29
  requirement: !ruby/object:Gem::Requirement
@@ -50,28 +44,28 @@ dependencies:
50
44
  requirements:
51
45
  - - "~>"
52
46
  - !ruby/object:Gem::Version
53
- version: 3.0.beta
47
+ version: '3'
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
51
  requirements:
58
52
  - - "~>"
59
53
  - !ruby/object:Gem::Version
60
- version: 3.0.beta
54
+ version: '3'
61
55
  - !ruby/object:Gem::Dependency
62
56
  name: guard-rspec
63
57
  requirement: !ruby/object:Gem::Requirement
64
58
  requirements:
65
- - - ">="
59
+ - - "~>"
66
60
  - !ruby/object:Gem::Version
67
- version: '0'
61
+ version: '4'
68
62
  type: :development
69
63
  prerelease: false
70
64
  version_requirements: !ruby/object:Gem::Requirement
71
65
  requirements:
72
- - - ">="
66
+ - - "~>"
73
67
  - !ruby/object:Gem::Version
74
- version: '0'
68
+ version: '4'
75
69
  description:
76
70
  email:
77
71
  - ronie.uliana@vagas.com.br
@@ -93,11 +87,13 @@ files:
93
87
  - lib/pascoale.rb
94
88
  - lib/pascoale/constants.rb
95
89
  - lib/pascoale/edits.rb
90
+ - lib/pascoale/formatter.rb
96
91
  - lib/pascoale/syllable_separator.rb
97
92
  - lib/pascoale/syllable_separator_benchmark.rb
98
93
  - lib/pascoale/version.rb
99
94
  - pascoale.gemspec
100
95
  - spec/lib/pascoale/edits_spec.rb
96
+ - spec/lib/pascoale/formatter_spec.rb
101
97
  - spec/lib/pascoale/syllable_separator_spec.rb
102
98
  - spec/spec_helper.rb
103
99
  homepage: http://github.com/ruliana/pascoale
@@ -120,11 +116,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
120
116
  version: '0'
121
117
  requirements: []
122
118
  rubyforge_project:
123
- rubygems_version: 2.2.0
119
+ rubygems_version: 2.2.2
124
120
  signing_key:
125
121
  specification_version: 4
126
122
  summary: Text processing utilities for Brazilian Portuguese
127
123
  test_files:
128
124
  - spec/lib/pascoale/edits_spec.rb
125
+ - spec/lib/pascoale/formatter_spec.rb
129
126
  - spec/lib/pascoale/syllable_separator_spec.rb
130
127
  - spec/spec_helper.rb