conchiterz 0.1.0 → 1.1.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 +4 -4
- data/README.md +80 -9
- data/conchiterz.gemspec +1 -1
- data/lib/conchiterz.rb +51 -42
- data/lib/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ee101a3c9eed10ffbb0419afabf1c4b40e188a28
|
4
|
+
data.tar.gz: e362d4b393b102c901cf7036efec5c01aa8ff4b5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5df116760ea45ee392b0a75c9cf3c18bf7ad8340a4df2374e2a135475bfd1de2a28f35c3a90f9c617d9db96aff9d684d60565b097ea320c73f9f10b61278df16
|
7
|
+
data.tar.gz: 02cd0f10d29808a50dfd1eaca6dd549dc904a7143661b4622530de71afd612df5ea235c398306fb2a52213aef6cb5d7a8b08b84dfd8bdf03f9ff870f8dd1a43b
|
data/README.md
CHANGED
@@ -1,8 +1,13 @@
|
|
1
|
+
[](https://badge.fury.io/rb/conchiterz)
|
2
|
+
|
1
3
|
# Conchiterz
|
2
4
|
|
3
|
-
|
5
|
+
A simply gem to feminize french word and french sentence.
|
4
6
|
|
5
|
-
|
7
|
+
* Keep intact upcase, downcase and capitalize letters
|
8
|
+
* Hanfle numbers
|
9
|
+
* Keep intact punctuation
|
10
|
+
* Handle special characters
|
6
11
|
|
7
12
|
## Installation
|
8
13
|
|
@@ -20,22 +25,88 @@ Or install it yourself as:
|
|
20
25
|
|
21
26
|
$ gem install conchiterz
|
22
27
|
|
23
|
-
##
|
28
|
+
## Get started
|
29
|
+
`Conchiterz.translate(string, boolean, escape = [])` feminize a french string if boolean is evaluates to true.
|
30
|
+
|
31
|
+
Use on your CLI :
|
32
|
+
```ruby
|
33
|
+
[1] pry(main)> require 'conchiterz'
|
34
|
+
=> true
|
35
|
+
[2] pry(main)> Conchiterz.translate('Vous vous êtes inscrit avec succès.', true)
|
36
|
+
=> "Vous vous êtes inscrite avec succès."
|
37
|
+
```
|
38
|
+
|
39
|
+
If you give feminine string whatever the boolean value, the same string will be returned.
|
40
|
+
|
41
|
+
### Escaping words
|
42
|
+
|
43
|
+
Sometimes in french you should have the need to not feminize some word in function of the context of your sentence.
|
44
|
+
|
45
|
+
Take the following code and sentence:
|
46
|
+
|
47
|
+
```ruby
|
48
|
+
Conchiterz.translate('Nous vous souhaitons un joyeux réveillon, soyez heureux en 2018'
|
49
|
+
, true)
|
50
|
+
```
|
51
|
+
|
52
|
+
We don't want the following result:
|
53
|
+
|
54
|
+
```ruby
|
55
|
+
'Nous vous souhaitons une joyeuse réveillon, soyez heureuse en 2018'
|
56
|
+
```
|
57
|
+
Because 'un joyeux réveillon' is invariable in french.
|
58
|
+
|
59
|
+
In this way let's introduce the escape option.
|
60
|
+
|
61
|
+
Just add an array of which words you not wanted to feminize, check the following code:
|
62
|
+
|
63
|
+
```ruby
|
64
|
+
[1] pry(main)> require 'conchiterz'
|
65
|
+
=> true
|
66
|
+
[2] pry(main)> Conchiterz.translate('Nous vous souhaitons un joyeux réveillon, soyez heureux en 2018'
|
67
|
+
, true, ['un', 'joyeux'])
|
68
|
+
=> 'Nous vous souhaitons un joyeux réveillon, soyez heureuse en 2018'
|
69
|
+
```
|
70
|
+
Et voila! Easy to feminize your sentence still understandable by french speaker.
|
71
|
+
|
72
|
+
## Rails
|
73
|
+
|
74
|
+
It adds String#conchiterz(boolean, escape = [])
|
75
|
+
|
76
|
+
If you just want to feminize a sentence add in your view,
|
77
|
+
|
78
|
+
```ruby
|
79
|
+
# app/views/pratiquants/show.html.erb
|
80
|
+
|
81
|
+
<%= 'Vous êtes bien inscrit à notre newsletter.'.conchiterz(@pratiquant.female?) %>
|
82
|
+
```
|
83
|
+
Will return
|
24
84
|
|
25
|
-
|
85
|
+
```ruby
|
86
|
+
"Vous êtes bien inscrite à notre newsletter."
|
87
|
+
```
|
88
|
+
if your pratiquant is a female.
|
26
89
|
|
27
|
-
|
90
|
+
### Escaping words
|
28
91
|
|
29
|
-
|
92
|
+
You wanted to escape some words? Just add these words inside an array and pass it as argument, as follow..
|
30
93
|
|
31
|
-
|
94
|
+
```ruby
|
95
|
+
# app/views/pratiquants/show.html.erb
|
96
|
+
|
97
|
+
<%= 'Nous vous souhaitons un joyeux réveillon et soyez heureux en 2018'.conchiterz(@pratiquant.female?,['un', 'joyeux']) %>
|
98
|
+
```
|
99
|
+
Will return
|
100
|
+
|
101
|
+
```ruby
|
102
|
+
'Nous vous souhaitons un joyeux réveillon et soyez heureuse en 2018'
|
103
|
+
```
|
32
104
|
|
33
105
|
## Contributing
|
34
106
|
|
35
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
107
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/morissetcl/conchiterz. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
36
108
|
|
37
109
|
|
38
110
|
## License
|
39
111
|
|
40
112
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
41
|
-
|
data/conchiterz.gemspec
CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
|
|
10
10
|
spec.email = ["morissetcl87@gmail.com"]
|
11
11
|
|
12
12
|
spec.homepage = "https://github.com/morissetcl/conchiterz"
|
13
|
-
spec.summary = "Conchiterz
|
13
|
+
spec.summary = "Conchiterz allows you to feminize french sentence"
|
14
14
|
spec.license = "MIT"
|
15
15
|
spec.add_development_dependency "rspec", "~> 3.2"
|
16
16
|
|
data/lib/conchiterz.rb
CHANGED
@@ -1,16 +1,18 @@
|
|
1
1
|
module Conchiterz
|
2
|
+
extend self
|
3
|
+
|
2
4
|
module StringMethods
|
3
|
-
def conchiterz(
|
5
|
+
def conchiterz(switch, escape = [])
|
6
|
+
Conchiterz.translate(self, switch, escape)
|
7
|
+
end
|
4
8
|
end
|
5
|
-
|
6
|
-
def
|
9
|
+
|
10
|
+
def translate(string, switch, escape = [])
|
7
11
|
return if string.nil?
|
8
12
|
result = []
|
9
|
-
a_words = string.scan(/[[:alpha:]]+|[.,!?']+/)
|
10
|
-
if
|
11
|
-
a_words.each
|
12
|
-
analyze_string(word, result)
|
13
|
-
end
|
13
|
+
a_words = string.scan(/[[:alpha:][:digit:]]+|[.,!?';]+/)
|
14
|
+
if switch == true
|
15
|
+
a_words.each{ |word| analyze_string(word, result, escape) }
|
14
16
|
check_punctuation(result)
|
15
17
|
check_special_character(result)
|
16
18
|
result.join(' ')
|
@@ -19,22 +21,24 @@ module Conchiterz
|
|
19
21
|
end
|
20
22
|
end
|
21
23
|
|
22
|
-
def
|
23
|
-
|
24
|
+
def monkey_patch(str)
|
25
|
+
str.send(:include, Conchiterz::StringMethods)
|
24
26
|
end
|
25
27
|
|
26
28
|
private
|
27
29
|
|
28
|
-
def
|
30
|
+
def analyze_string(word, result, escape)
|
29
31
|
check_word_length(word)
|
30
|
-
if TRANSLATION.has_key?(word.downcase)
|
32
|
+
if TRANSLATION.has_key?(word.downcase) && escape.include?(word)
|
33
|
+
result.push(word)
|
34
|
+
elsif TRANSLATION.has_key?(word.downcase)
|
31
35
|
get_value(@capitalized, @upcased, result, word)
|
32
36
|
else
|
33
37
|
result.push(word)
|
34
38
|
end
|
35
39
|
end
|
36
40
|
|
37
|
-
def
|
41
|
+
def check_word_length(word)
|
38
42
|
if word.length == 1
|
39
43
|
@capitalized = (word == word.capitalize)
|
40
44
|
else
|
@@ -43,59 +47,58 @@ module Conchiterz
|
|
43
47
|
end
|
44
48
|
end
|
45
49
|
|
46
|
-
def
|
47
|
-
key = TRANSLATION.key(word.downcase)
|
48
|
-
add_value_to_result(capitalized, upcased, key, result)
|
49
|
-
end
|
50
|
-
|
51
|
-
def self.get_value(capitalized, upcased, result, word)
|
50
|
+
def get_value(capitalized, upcased, result, word)
|
52
51
|
value = TRANSLATION.fetch(word.downcase)
|
53
52
|
add_value_to_result(capitalized, upcased, value, result)
|
54
53
|
end
|
55
54
|
|
56
|
-
def
|
55
|
+
def add_value_to_result(capitalized, upcased, value, result)
|
57
56
|
if check_sensitive(capitalized, upcased) == false
|
58
|
-
result <<
|
57
|
+
result << value
|
59
58
|
else
|
60
|
-
capitalize_or_upcase
|
59
|
+
capitalize_or_upcase(capitalized, upcased, value, result)
|
61
60
|
end
|
62
61
|
end
|
63
62
|
|
64
|
-
def
|
65
|
-
return
|
63
|
+
def check_sensitive(capitalized, upcased)
|
64
|
+
return if (capitalized == true || upcased == true)
|
66
65
|
false
|
67
66
|
end
|
68
67
|
|
69
|
-
def
|
70
|
-
result <<
|
71
|
-
result <<
|
68
|
+
def capitalize_or_upcase(capitalized, upcased, value, result)
|
69
|
+
result << value.capitalize if capitalized
|
70
|
+
result << value.upcase if upcased
|
72
71
|
end
|
73
72
|
|
74
|
-
def
|
73
|
+
def check_punctuation(result)
|
74
|
+
punctuation = [',','.','!',':',';','?']
|
75
75
|
result.each_with_index do |val, index|
|
76
|
-
if val
|
77
|
-
|
78
|
-
result[
|
79
|
-
result.delete(result[
|
76
|
+
if punctuation.include?(val)
|
77
|
+
index = result.index(val)
|
78
|
+
result[index].insert(0, result[index-1])
|
79
|
+
result.delete(result[index-1])
|
80
80
|
end
|
81
81
|
end
|
82
82
|
end
|
83
83
|
|
84
|
-
def
|
84
|
+
def check_special_character(result)
|
85
85
|
result.each_with_index do |val, index|
|
86
86
|
if val == "'"
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
d = result[result.index(c)+1]
|
92
|
-
v = result[result.index(c)-1]
|
93
|
-
result.delete_at(result.index(v))
|
94
|
-
result.delete_at(result.index(c)+1)
|
87
|
+
index = result.index(val)
|
88
|
+
word = [result[index-1], result[index], result[index+1]]
|
89
|
+
delete_useless_value(word, index, result)
|
90
|
+
result.insert(index-1, word.join(''))
|
95
91
|
end
|
96
92
|
end
|
97
93
|
end
|
98
94
|
|
95
|
+
def delete_useless_value(word, index, result)
|
96
|
+
word.each do |a|
|
97
|
+
index_to_delete = result.index(a)
|
98
|
+
result.delete_at(index_to_delete)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
99
102
|
TRANSLATION =
|
100
103
|
{
|
101
104
|
'beau' => 'belle',
|
@@ -111,7 +114,13 @@ module Conchiterz
|
|
111
114
|
'pareils' => 'pareilles',
|
112
115
|
'monsieur' => 'madame',
|
113
116
|
'm' => 'mme',
|
114
|
-
'le' => 'la'
|
117
|
+
'le' => 'la',
|
118
|
+
'chers' => 'chères',
|
119
|
+
'cher' => 'chère',
|
120
|
+
'bon' => 'bonne',
|
121
|
+
'super' => 'superbe',
|
122
|
+
'un' => 'une',
|
123
|
+
'heureux' => 'heureuse'
|
115
124
|
}
|
116
125
|
|
117
126
|
end
|
data/lib/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: conchiterz
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Clement Morisset
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-12-
|
11
|
+
date: 2017-12-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -93,5 +93,5 @@ rubyforge_project:
|
|
93
93
|
rubygems_version: 2.5.1
|
94
94
|
signing_key:
|
95
95
|
specification_version: 4
|
96
|
-
summary: Conchiterz
|
96
|
+
summary: Conchiterz allows you to feminize french sentence
|
97
97
|
test_files: []
|