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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: be84ab885dd8973f26a64ecf6ad23734b6e08787
4
- data.tar.gz: 7068a21dd3fc268dd5a3a0cc39521d649123823d
3
+ metadata.gz: ee101a3c9eed10ffbb0419afabf1c4b40e188a28
4
+ data.tar.gz: e362d4b393b102c901cf7036efec5c01aa8ff4b5
5
5
  SHA512:
6
- metadata.gz: 5c58df5235a39e99baa52aa3f192014d0d6ab50736700c4b49773344962574f1f3401254efdbca12e07617c145501d45a740f2cd6c02a682f624d7c5115377f0
7
- data.tar.gz: b7b876230d9d6f6a71062e86bd9938e05e7639c56634483d01625025e9ab0e15d27cd521afe80b03ae0988f71b61c6b65758507f31e51388d82f51804aaebb16
6
+ metadata.gz: 5df116760ea45ee392b0a75c9cf3c18bf7ad8340a4df2374e2a135475bfd1de2a28f35c3a90f9c617d9db96aff9d684d60565b097ea320c73f9f10b61278df16
7
+ data.tar.gz: 02cd0f10d29808a50dfd1eaca6dd549dc904a7143661b4622530de71afd612df5ea235c398306fb2a52213aef6cb5d7a8b08b84dfd8bdf03f9ff870f8dd1a43b
data/README.md CHANGED
@@ -1,8 +1,13 @@
1
+ [![Gem Version](https://badge.fury.io/rb/conchiterz.svg)](https://badge.fury.io/rb/conchiterz)
2
+
1
3
  # Conchiterz
2
4
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/conchiterz`. To experiment with that code, run `bin/console` for an interactive prompt.
5
+ A simply gem to feminize french word and french sentence.
4
6
 
5
- TODO: Delete this and the text above, and describe your gem
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
- ## Usage
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
- TODO: Write usage instructions here
85
+ ```ruby
86
+ "Vous êtes bien inscrite à notre newsletter."
87
+ ```
88
+ if your pratiquant is a female.
26
89
 
27
- ## Development
90
+ ### Escaping words
28
91
 
29
- After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
92
+ You wanted to escape some words? Just add these words inside an array and pass it as argument, as follow..
30
93
 
31
- 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).
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/[USERNAME]/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.
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
-
@@ -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 allow you to feminize french word/sentence"
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
 
@@ -1,16 +1,18 @@
1
1
  module Conchiterz
2
+ extend self
3
+
2
4
  module StringMethods
3
- def conchiterz(boolean); Conchiterz.translate(self, boolean); end
5
+ def conchiterz(switch, escape = [])
6
+ Conchiterz.translate(self, switch, escape)
7
+ end
4
8
  end
5
-
6
- def self.translate(string, boolean)
9
+
10
+ def translate(string, switch, escape = [])
7
11
  return if string.nil?
8
12
  result = []
9
- a_words = string.scan(/[[:alpha:]]+|[.,!?']+/)
10
- if boolean == true
11
- a_words.each do |word|
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 self.monkey_patch(mod)
23
- mod.send(:include, Conchiterz::StringMethods)
24
+ def monkey_patch(str)
25
+ str.send(:include, Conchiterz::StringMethods)
24
26
  end
25
27
 
26
28
  private
27
29
 
28
- def self.analyze_string(word, result)
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 self.check_word_length(word)
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 self.get_key(capitalized, upcased, result, word)
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 self.add_value_to_result(capitalized, upcased, type, result)
55
+ def add_value_to_result(capitalized, upcased, value, result)
57
56
  if check_sensitive(capitalized, upcased) == false
58
- result << type
57
+ result << value
59
58
  else
60
- capitalize_or_upcase?(capitalized, upcased, type, result)
59
+ capitalize_or_upcase(capitalized, upcased, value, result)
61
60
  end
62
61
  end
63
62
 
64
- def self.check_sensitive(capitalized, upcased)
65
- return unless (capitalized == false && upcased == false)
63
+ def check_sensitive(capitalized, upcased)
64
+ return if (capitalized == true || upcased == true)
66
65
  false
67
66
  end
68
67
 
69
- def self.capitalize_or_upcase?(capitalized, upcased, type, result)
70
- result << type.capitalize if capitalized
71
- result << type.upcase if upcased
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 self.check_punctuation(result)
73
+ def check_punctuation(result)
74
+ punctuation = [',','.','!',':',';','?']
75
75
  result.each_with_index do |val, index|
76
- if val == ',' || val == '.'
77
- a = result.index(val)
78
- result[a].insert(0, result[a-1])
79
- result.delete(result[a-1])
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 self.check_special_character(result)
84
+ def check_special_character(result)
85
85
  result.each_with_index do |val, index|
86
86
  if val == "'"
87
- a = result.index(val)
88
- b = result[a].insert(0, result[a-1])
89
- index1 = result.index(b)
90
- c = result[index1].insert(-1, result[index1+1])
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
@@ -1,3 +1,3 @@
1
1
  module Conchiterz
2
- VERSION = "0.1.0"
2
+ VERSION = "1.1.0"
3
3
  end
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: 0.1.0
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-10 00:00:00.000000000 Z
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 allow you to feminize french word/sentence
96
+ summary: Conchiterz allows you to feminize french sentence
97
97
  test_files: []