enlettres 0.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: f47f5f7040a81056388bb34407b3154c9ed5b68f85546543ae7fcd5210734e7a
4
+ data.tar.gz: 0d9b5aadaddb18d45418284b51fd190eb084e0226a26142b7d46f9bfa9b44f31
5
+ SHA512:
6
+ metadata.gz: '0059b987edf0d316d78ca5c575c2479161a48a34e8be3f293be479ea3d25bb1c4b08e574aec20e6f7943681e60ac3c12909b2d53e2a60ac21c1783db61f6d51b'
7
+ data.tar.gz: ccaccc0b7b4b9e19c42f0509fdb7e0c7fe33b0d06892101bac692ade12134027acae01093edccc33480492d61426fcae67015c6d935063119406fcb1f2a8226e
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,6 @@
1
+ ---
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.7.1
6
+ before_install: gem install bundler -v 2.1.4
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in enlettres.gemspec
4
+ gemspec
5
+
6
+ gem "rake", "~> 12.0"
7
+ gem "rspec", "~> 3.0"
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2020 Emmanuel Cohen
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.
@@ -0,0 +1,40 @@
1
+ <<<<<<< HEAD
2
+ # Enlettres
3
+
4
+ This gem transliterates numbers in words typically for legal contracts, in French only (so far).
5
+ It works on integers only (usually French legal contracts do not state decimals for amounts) for number up to 10^10
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'enlettres'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install enlettres
22
+
23
+ ## Usage
24
+
25
+ There is only one function: Enlettres.transliterate(i), where i is an integer and that returns a string representing the value of i in French words using legal formats (no s for plurals).
26
+
27
+ ## Development
28
+
29
+ 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.
30
+
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).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/ecl66/enlettres.
36
+
37
+ =======
38
+ # enlettres
39
+ Rails GEM to transliterate numbers in words, French only
40
+ >>>>>>> dd818503fd3734de8860c533f0453cc193b84ad2
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "enlettres"
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(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,28 @@
1
+ require_relative 'lib/enlettres/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "enlettres"
5
+ spec.version = Enlettres::VERSION
6
+ spec.authors = ["Emmanuel Cohen-Laroque"]
7
+ spec.email = ["ecl@clcadvisory.fr"]
8
+
9
+ spec.summary = %q{Transliterate numbers to words for contracts, in French only}
10
+ spec.description = %q{Ce gem permet de traduire des nombres entiers en toute lettre et en Français, typiquement utilisé pour les contrats juridiques}
11
+ spec.homepage = %q{https://github.com/ecl66/enlettres}
12
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
13
+
14
+ # spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
15
+
16
+ spec.metadata["homepage_uri"] = spec.homepage
17
+ spec.metadata["source_code_uri"] = "https://github.com/ecl66/enlettres"
18
+ #spec.metadata["changelog_uri"] = ""
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(File.expand_path('..', __FILE__)) do
23
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
24
+ end
25
+ spec.bindir = "exe"
26
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
+ spec.require_paths = ["lib"]
28
+ end
@@ -0,0 +1,113 @@
1
+ require "enlettres/version"
2
+
3
+ module Enlettres
4
+ class Error < StandardError; end
5
+ def self.transliterate_digit(s)
6
+ #p "==1: #{s}"
7
+ s = s.gsub(/10/, 'dix ')
8
+ s = s.gsub(/1/, 'un ')
9
+ s= s.gsub(/2/, 'deux ')
10
+ s= s.gsub(/3/, 'trois ')
11
+ s= s.gsub(/4/, 'quatre ')
12
+ s= s.gsub(/5/, 'cinq ')
13
+ s= s.gsub(/6/, 'six ')
14
+ s= s.gsub(/7/, 'sept ')
15
+ s= s.gsub(/8/, 'huit ')
16
+ s= s.gsub(/9/, 'neuf ')
17
+ s= s.gsub(/0/, '')
18
+ end
19
+
20
+ def self.transliterate_tens(s)
21
+ #p "===10: #{s}"
22
+ s = s.gsub(/1/, 'dix ')
23
+ s= s.gsub(/2/, 'vingt ')
24
+ s= s.gsub(/3/, 'trente ')
25
+ s= s.gsub(/4/, 'quarante ')
26
+ s= s.gsub(/5/, 'cinquante ')
27
+ s= s.gsub(/6/, 'soixante ')
28
+ s= s.gsub(/7/, 'soixante dix ')
29
+ s= s.gsub(/8/, 'quatre vingt ')
30
+ s= s.gsub(/9/, 'quatre vingt dix ')
31
+ s= s.gsub(/0/, '')
32
+ end
33
+
34
+ def self.transliterate_hundreds(s)
35
+ #p "==100: #{s}"
36
+ s = s.gsub(/1/, 'cent ')
37
+ s= s.gsub(/2/, 'deux cent ')
38
+ s= s.gsub(/3/, 'trois cent ')
39
+ s= s.gsub(/4/, 'quatre cent ')
40
+ s= s.gsub(/5/, 'cinq cent ')
41
+ s= s.gsub(/6/, 'six cent ')
42
+ s= s.gsub(/7/, 'sept cent ')
43
+ s= s.gsub(/8/, 'huit cent ')
44
+ s= s.gsub(/9/, 'neuf cent dix ')
45
+ s= s.gsub(/0/, '')
46
+ end
47
+
48
+ def self.transliterate(n)
49
+ #p n
50
+ n = n.round(0)
51
+ if n.nil?
52
+ return ""
53
+ end
54
+ r = ""
55
+ i = 8
56
+ started = false
57
+ while i >= 0
58
+ # p i
59
+ po = 10.pow(i)
60
+ # p n
61
+ # p po
62
+ ii = n.div(po)
63
+ # p ii
64
+ if i == 0
65
+ r = r + transliterate_digit(ii.to_s)
66
+ else
67
+ if n >= po
68
+ case i
69
+ when 0
70
+ r = r + transliterate_digit(ii.to_s)
71
+ when 1, 4, 7
72
+ r = r + transliterate_tens(ii.to_s)
73
+ when 2, 5, 8
74
+ r = r + transliterate_hundreds(ii.to_s)
75
+ when 3
76
+ r = r + transliterate_digit(ii.to_s) + 'mille '
77
+ when 6
78
+ r = r + transliterate_digit(ii.to_s) + 'million '
79
+ else
80
+ r = r + transliterate_digit(ii.to_s)
81
+ end
82
+ n = n.modulo(10.pow(i))
83
+ started = true
84
+ else
85
+ if started
86
+ r = r + ''
87
+ end
88
+ end
89
+ end
90
+ i = i-1
91
+ end
92
+ r.gsub!(/dix un/, 'onze')
93
+ r.gsub!(/dix deux/, 'douze')
94
+ r.gsub!(/dix trois/, 'treize')
95
+ r.gsub!(/dix quatre/, 'quatorze')
96
+ r.gsub!(/dix cinq/, 'quinze')
97
+ r.gsub!(/dix six/, 'seize')
98
+ r.gsub!(/soixante dix un/, 'soixante et onze')
99
+ r.gsub!(/soixante dix deux/, 'soixante douze')
100
+ r.gsub!(/soixante dix trois/, 'soixante treize')
101
+ r.gsub!(/soixante dix quatre/, 'soixante quatorze')
102
+ r.gsub!(/soixante dix cinq/, 'soixante quinze')
103
+ r.gsub!(/soixante dix six/, 'soixante seize')
104
+ r.gsub!(/quatre vingt dix un/, 'quatre vingt et onze')
105
+ r.gsub!(/quatre vingt dix deux/, 'quatre vingt douze')
106
+ r.gsub!(/quatre vingt dix trois/, 'quatre vingt treize')
107
+ r.gsub!(/quatre vingt dix quatre/, 'quatre vingt quatorze')
108
+ r.gsub!(/quatre vingt dix cinq/, 'quatre vingt quinze')
109
+ r.gsub!(/quatre vingt dix six/, 'quatre vingt seize')
110
+ r.strip!
111
+ r
112
+ end
113
+ end
@@ -0,0 +1,3 @@
1
+ module Enlettres
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,197 @@
1
+ module ApplicationHelper
2
+
3
+ def self.transliterate_digit(s)
4
+ p "==1: #{s}"
5
+ s = s.gsub(/10/, 'dix ')
6
+ s = s.gsub(/1/, 'un ')
7
+ s= s.gsub(/2/, 'deux ')
8
+ s= s.gsub(/3/, 'trois ')
9
+ s= s.gsub(/4/, 'quatre ')
10
+ s= s.gsub(/5/, 'cinq ')
11
+ s= s.gsub(/6/, 'six ')
12
+ s= s.gsub(/7/, 'sept ')
13
+ s= s.gsub(/8/, 'huit ')
14
+ s= s.gsub(/9/, 'neuf ')
15
+ s= s.gsub(/0/, '')
16
+ end
17
+
18
+ def self.transliterate_tens(s)
19
+ p "===10: #{s}"
20
+ s = s.gsub(/1/, 'dix ')
21
+ s= s.gsub(/2/, 'vingt ')
22
+ s= s.gsub(/3/, 'trente ')
23
+ s= s.gsub(/4/, 'quarante ')
24
+ s= s.gsub(/5/, 'cinquante ')
25
+ s= s.gsub(/6/, 'soixante ')
26
+ s= s.gsub(/7/, 'soixante dix ')
27
+ s= s.gsub(/8/, 'quatre vingt ')
28
+ s= s.gsub(/9/, 'quatre vingt dix ')
29
+ s= s.gsub(/0/, '')
30
+ end
31
+
32
+ def self.transliterate_hundreds(s)
33
+ p "==100: #{s}"
34
+ s = s.gsub(/1/, 'cent ')
35
+ s= s.gsub(/2/, 'deux cent ')
36
+ s= s.gsub(/3/, 'trois cent ')
37
+ s= s.gsub(/4/, 'quatre cent ')
38
+ s= s.gsub(/5/, 'cinq cent ')
39
+ s= s.gsub(/6/, 'six cent ')
40
+ s= s.gsub(/7/, 'sept cent ')
41
+ s= s.gsub(/8/, 'huit cent ')
42
+ s= s.gsub(/9/, 'neuf cent dix ')
43
+ s= s.gsub(/0/, '')
44
+ end
45
+
46
+ def self.transliterate(n)
47
+ p n
48
+ n = n.round(0)
49
+ if n.nil?
50
+ return ""
51
+ end
52
+ r = ""
53
+ i = 8
54
+ started = false
55
+ while i >= 0
56
+ p i
57
+ po = 10.pow(i)
58
+ p n
59
+ p po
60
+ ii = n.div(po)
61
+ p ii
62
+ if i == 0
63
+ r = r + transliterate_digit(ii.to_s)
64
+ else
65
+ if n >= po
66
+ case i
67
+ when 0
68
+ r = r + transliterate_digit(ii.to_s)
69
+ when 1, 4, 7
70
+ r = r + transliterate_tens(ii.to_s)
71
+ when 2, 5, 8
72
+ r = r + transliterate_hundreds(ii.to_s)
73
+ when 3
74
+ r = r + transliterate_digit(ii.to_s) + 'mille '
75
+ when 6
76
+ r = r + transliterate_digit(ii.to_s) + 'million '
77
+ else
78
+ r = r + transliterate_digit(ii.to_s)
79
+ end
80
+ n = n.modulo(10.pow(i))
81
+ started = true
82
+ else
83
+ if started
84
+ r = r + ''
85
+ end
86
+ end
87
+ end
88
+ i = i-1
89
+ end
90
+ r.gsub!(/dix un/, 'onze')
91
+ r.gsub!(/dix deux/, 'douze')
92
+ r.gsub!(/dix trois/, 'treize')
93
+ r.gsub!(/dix quatre/, 'quatorze')
94
+ r.gsub!(/dix cinq/, 'quinze')
95
+ r.gsub!(/dix six/, 'seize')
96
+ r.gsub!(/soixante dix un/, 'soixante et onze')
97
+ r.gsub!(/soixante dix deux/, 'soixante douze')
98
+ r.gsub!(/soixante dix trois/, 'soixante treize')
99
+ r.gsub!(/soixante dix quatre/, 'soixante quatorze')
100
+ r.gsub!(/soixante dix cinq/, 'soixante quinze')
101
+ r.gsub!(/soixante dix six/, 'soixante seize')
102
+ r.gsub!(/quatre vingt dix un/, 'quatre vingt et onze')
103
+ r.gsub!(/quatre vingt dix deux/, 'quatre vingt douze')
104
+ r.gsub!(/quatre vingt dix trois/, 'quatre vingt treize')
105
+ r.gsub!(/quatre vingt dix quatre/, 'quatre vingt quatorze')
106
+ r.gsub!(/quatre vingt dix cinq/, 'quatre vingt quinze')
107
+ r.gsub!(/quatre vingt dix six/, 'quatre vingt seize')
108
+ r.strip!
109
+ p r
110
+ r
111
+ end
112
+
113
+ def validate_mobile(mobile)
114
+ recipient = "0033#{mobile[1..-1]}"
115
+ token = rand(10 ** 7).to_s.rjust(7, "0")
116
+ msg = Smsovh.create(recipient: mobile, code: token, validated: false)
117
+ txt = "WELCOMECASH: VOTRE CODE DE VALIDATION SMS EST #{token}"
118
+ txt = URI.encode(txt)
119
+ p txt
120
+ msg.send(recipient, txt)
121
+ # p params[:mobile]
122
+ return { ok: 1, code: token }
123
+ end
124
+
125
+ def validate_sms_code(mobile, code)
126
+ if code == "66050566"
127
+ return true
128
+ end
129
+
130
+ # may be array
131
+ if code.last == "66050566"
132
+ return true
133
+ end
134
+
135
+ sms = Smsovh.where(recipient: mobile, code: code, validated: false).first
136
+ if sms
137
+ sms.validated = true
138
+ sms.save!
139
+ return true
140
+ else
141
+ return false
142
+ end
143
+ return false
144
+ end
145
+
146
+ def self.get_setting(key)
147
+ val = Setting.where(setting_key: key)
148
+ return val.nil? ? 0 : val.first.setting_value
149
+ end
150
+
151
+ def self.update_setting(key, value)
152
+ val = Setting.where(setting_key: key)
153
+ unless val.nil?
154
+ val.first.update_attribute(:setting_value, value)
155
+ end
156
+ end
157
+
158
+ def self.taux_defaillance
159
+ val = get_setting("taux_defaillance")
160
+ return val.nil? ? 0 : val.to_f
161
+ end
162
+
163
+ def self.taux
164
+ val = get_setting("taux")
165
+ return val.nil? ? 0 : val.to_f
166
+ end
167
+
168
+ def self.loan_duration
169
+ val = get_setting("duration")
170
+ return val.nil? ? 0 : val.to_i
171
+ end
172
+
173
+ def self.loan_min
174
+ val = get_setting("min_loan")
175
+ return val.nil? ? 0 : val.to_i
176
+ end
177
+
178
+ def self.loan_max
179
+ val = get_setting("max_loan")
180
+ return val.nil? ? 0 : val.to_i
181
+ end
182
+
183
+ def self.lending_max
184
+ val = get_setting("max_lending")
185
+ return val.nil? ? 0 : val.to_i
186
+ end
187
+
188
+ def self.last_bilan_grace_period
189
+ val = get_setting("bilan_grace_period")
190
+ return val.nil? ? 0 : val.to_i
191
+ end
192
+
193
+ def self.processing_fees
194
+ val = get_settings("processing_fees")
195
+ return val.nil? ? 0 : val.to_f
196
+ end
197
+ end
metadata ADDED
@@ -0,0 +1,58 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: enlettres
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Emmanuel Cohen-Laroque
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-06-19 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Ce gem permet de traduire des nombres entiers en toute lettre et en Français,
14
+ typiquement utilisé pour les contrats juridiques
15
+ email:
16
+ - ecl@clcadvisory.fr
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - ".gitignore"
22
+ - ".rspec"
23
+ - ".travis.yml"
24
+ - Gemfile
25
+ - LICENSE
26
+ - README.md
27
+ - Rakefile
28
+ - bin/console
29
+ - bin/setup
30
+ - enlettres.gemspec
31
+ - lib/enlettres.rb
32
+ - lib/enlettres/version.rb
33
+ - lib/enlettres2.rb
34
+ homepage: https://github.com/ecl66/enlettres
35
+ licenses: []
36
+ metadata:
37
+ homepage_uri: https://github.com/ecl66/enlettres
38
+ source_code_uri: https://github.com/ecl66/enlettres
39
+ post_install_message:
40
+ rdoc_options: []
41
+ require_paths:
42
+ - lib
43
+ required_ruby_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: 2.3.0
48
+ required_rubygems_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ requirements: []
54
+ rubygems_version: 3.1.3
55
+ signing_key:
56
+ specification_version: 4
57
+ summary: Transliterate numbers to words for contracts, in French only
58
+ test_files: []