doc_tien 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/CODE_OF_CONDUCT.md +49 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +74 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/doc_tien.gemspec +32 -0
- data/lib/doc_tien.rb +100 -0
- data/lib/doc_tien/version.rb +3 -0
- metadata +84 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 4470e4b60b50e118d0583bbfb819c0375c7042ac
|
4
|
+
data.tar.gz: 278fa72184629d7198b7ffd3889bf8871e456878
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 28db2d49b4f99fb4f4ca4f4aee83dd91ed95611e9aa21bee60d5a0d22b6eec4b085dd75cb5772682bec4c2424a47197c3ef079f4786b0c5383e87c57d7d4f516
|
7
|
+
data.tar.gz: 66a9f62c66558de5de35661b5979906e2aa14f49af773f8ca5ad26ea911d9eaa71fcb226d1d5e943dff19de2cf53c7fde281b8154783b8a2d82c6970185d8c73
|
data/.gitignore
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, and in the interest of
|
4
|
+
fostering an open and welcoming community, we pledge to respect all people who
|
5
|
+
contribute through reporting issues, posting feature requests, updating
|
6
|
+
documentation, submitting pull requests or patches, and other activities.
|
7
|
+
|
8
|
+
We are committed to making participation in this project a harassment-free
|
9
|
+
experience for everyone, regardless of level of experience, gender, gender
|
10
|
+
identity and expression, sexual orientation, disability, personal appearance,
|
11
|
+
body size, race, ethnicity, age, religion, or nationality.
|
12
|
+
|
13
|
+
Examples of unacceptable behavior by participants include:
|
14
|
+
|
15
|
+
* The use of sexualized language or imagery
|
16
|
+
* Personal attacks
|
17
|
+
* Trolling or insulting/derogatory comments
|
18
|
+
* Public or private harassment
|
19
|
+
* Publishing other's private information, such as physical or electronic
|
20
|
+
addresses, without explicit permission
|
21
|
+
* Other unethical or unprofessional conduct
|
22
|
+
|
23
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
24
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
25
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
26
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
27
|
+
threatening, offensive, or harmful.
|
28
|
+
|
29
|
+
By adopting this Code of Conduct, project maintainers commit themselves to
|
30
|
+
fairly and consistently applying these principles to every aspect of managing
|
31
|
+
this project. Project maintainers who do not follow or enforce the Code of
|
32
|
+
Conduct may be permanently removed from the project team.
|
33
|
+
|
34
|
+
This code of conduct applies both within project spaces and in public spaces
|
35
|
+
when an individual is representing the project or its community.
|
36
|
+
|
37
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
38
|
+
reported by contacting a project maintainer at anvotien@gmail.com. All
|
39
|
+
complaints will be reviewed and investigated and will result in a response that
|
40
|
+
is deemed necessary and appropriate to the circumstances. Maintainers are
|
41
|
+
obligated to maintain confidentiality with regard to the reporter of an
|
42
|
+
incident.
|
43
|
+
|
44
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
45
|
+
version 1.3.0, available at
|
46
|
+
[http://contributor-covenant.org/version/1/3/0/][version]
|
47
|
+
|
48
|
+
[homepage]: http://contributor-covenant.org
|
49
|
+
[version]: http://contributor-covenant.org/version/1/3/0/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 TODO: Write your name
|
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,74 @@
|
|
1
|
+
# DocTien
|
2
|
+
|
3
|
+
Xin chào các bạn, tiếng Việt rất đẹp và theo một câu nói khá hay đó là những vấn đề của người Việt chỉ người Việt mới có thể giải quyết mà thôi.
|
4
|
+
|
5
|
+
En: This gem support for number to word (with currency) in Vietnamese.
|
6
|
+
|
7
|
+
Tôi là 1 lập trình viên Rails đang gặp 1 xíu vấn đề trong việc thực hiện tính năng "Số tiền bằng chữ: "
|
8
|
+
Qua quá trình tìm kiếm chưa thấy có một cách nào có sẵn hỗ trợ việc này.
|
9
|
+
|
10
|
+
Đó là lý do tôi viết thư viện này.
|
11
|
+
|
12
|
+
Giải quyết những việc như:
|
13
|
+
|
14
|
+
Nhập vào: 1453121401 -> Sẽ ra kết quả là: Một tỉ bốn trăm năm mươi ba triệu một trăm hai mươi mốt nghìn bốn trăm lẻ một đồng.
|
15
|
+
|
16
|
+
## Installation
|
17
|
+
|
18
|
+
Add this line to your application's Gemfile:
|
19
|
+
|
20
|
+
```ruby
|
21
|
+
gem 'doc_tien'
|
22
|
+
```
|
23
|
+
|
24
|
+
And then execute:
|
25
|
+
|
26
|
+
$ bundle
|
27
|
+
|
28
|
+
Or install it yourself as:
|
29
|
+
|
30
|
+
$ gem install doc_tien
|
31
|
+
|
32
|
+
## Usage
|
33
|
+
|
34
|
+
Rất đơn giản:
|
35
|
+
```ruby
|
36
|
+
DocTien.now(35000)
|
37
|
+
=> "Ba mươi lăm nghìn đồng"
|
38
|
+
```
|
39
|
+
```ruby
|
40
|
+
DocTien.now(1100000000, 'VND')
|
41
|
+
=> "Một tỉ một trăm triệu VND"
|
42
|
+
```
|
43
|
+
```ruby
|
44
|
+
DocTien.now("543000")
|
45
|
+
=> "Năm trăm bốn mươi ba nghìn đồng"
|
46
|
+
```
|
47
|
+
```ruby
|
48
|
+
DocTien.now(1453121407)
|
49
|
+
=> "Một tỉ bốn trăm năm mươi ba triệu một trăm hai mươi mốt nghìn bốn trăm lẻ bảy đồng"
|
50
|
+
```
|
51
|
+
```ruby
|
52
|
+
DocTien.now(1200000)
|
53
|
+
=> "Một triệu hai trăm nghìn đồng"
|
54
|
+
```
|
55
|
+
```ruby
|
56
|
+
DocTien.now(100000000)
|
57
|
+
=> "Một trăm triệu đồng"
|
58
|
+
```
|
59
|
+
|
60
|
+
## Development
|
61
|
+
|
62
|
+
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.
|
63
|
+
|
64
|
+
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).
|
65
|
+
|
66
|
+
## Contributing
|
67
|
+
|
68
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/doc_tien. 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.
|
69
|
+
|
70
|
+
|
71
|
+
## License
|
72
|
+
|
73
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
74
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "doc_tien"
|
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
|
data/bin/setup
ADDED
data/doc_tien.gemspec
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'doc_tien/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "doc_tien"
|
8
|
+
spec.version = DocTien::VERSION
|
9
|
+
spec.authors = ["Tiến An - thien.su.bs"]
|
10
|
+
spec.email = ["anvotien@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{ 125000: Một trăm hai mươi lăm nghìn đồng. Thư viện hỗ trợ việc này }
|
13
|
+
spec.description = %q{Thư viện hỗ trợ việc đọc tiền trong tiếng Việt. }
|
14
|
+
spec.homepage = "https://github.com/thiensubs/doc_tien"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
18
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
19
|
+
if spec.respond_to?(:metadata)
|
20
|
+
spec.metadata['allowed_push_host'] = "https://rubygems.org"
|
21
|
+
else
|
22
|
+
raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
23
|
+
end
|
24
|
+
|
25
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
26
|
+
spec.bindir = "exe"
|
27
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
|
+
spec.require_paths = ["lib"]
|
29
|
+
|
30
|
+
spec.add_development_dependency "bundler", "~> 1.12"
|
31
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
32
|
+
end
|
data/lib/doc_tien.rb
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
# require "doc_tien/version"
|
2
|
+
|
3
|
+
module DocTien
|
4
|
+
A = {0=> '',1 =>'một', 2=>'hai', 3=>'ba', 4=>'bốn', 5=>'năm', 6=>'sáu', 7=>'bảy', 8=>'tám', 9=>'chín'}
|
5
|
+
B = ['mười một', 'mười hai', 'mưòi ba', 'mười bốn', 'mười lăm', 'mười sáu', 'mười bảy',
|
6
|
+
'mười tám', 'mười chín' ]
|
7
|
+
C = {10=> 'mười', 20 => 'hai mươi',30=>'ba mươi',40=>'bốn mươi',50=>'năm mươi',60=>'sáu mươi',70=>'bảy mươi',
|
8
|
+
80=>'tám mươi',90=>'chín mươi'}
|
9
|
+
D = ['đồng.','nghìn','triệu','tỉ', "nghìn", 'triệu', 'tỉ' ]
|
10
|
+
E = ['trăm']
|
11
|
+
SPECIAL = {'trăm một' => 'trăm lẻ một', 'trăm hai' => 'trăm lẻ hai','trăm ba' => 'trăm lẻ ba',
|
12
|
+
'trăm bốn' => 'trăm lẻ bốn','trăm năm' => 'trăm lẻ năm','trăm sáu' => 'trăm lẻ sáu',
|
13
|
+
'trăm bảy' => 'trăm lẻ bảy','trăm tám' => 'trăm lẻ tám','trăm chín' => 'trăm lẻ chín' }
|
14
|
+
|
15
|
+
SPECIAL_2 = {'hai mươi một' => 'hai mươi mốt', 'ba mươi một' => 'ba mươi mốt',
|
16
|
+
'bốn mươi một' => 'bốn mươi mốt','năm mươi một' => 'năm mươi mốt',
|
17
|
+
'sáu mươi một' => 'sáu mươi mốt','bảy mươi một' => 'bảy mươi mốt',
|
18
|
+
'tám mươi một' => 'tám mươi mốt', 'chín mươi một' => 'chín mươi mốt' }
|
19
|
+
SPECIAL_3 = {'mười năm' => 'mười lăm', 'hai năm' => 'hai lăm',
|
20
|
+
'ba năm' => 'mười lăm','bốn năm' => 'bốn lăm',
|
21
|
+
'năm năm' => 'năm lăm','sáu năm' => 'sáu lăm',
|
22
|
+
'bảy năm' => 'bảy lăm', 'tám năm' => 'tám lăm', 'chín năm' => 'chín lăm', 'mươi năm' => 'mươi lăm' }
|
23
|
+
|
24
|
+
def self.now(s, char_currency='đồng')
|
25
|
+
s = s.to_s
|
26
|
+
# Split every 3 number to 1 block
|
27
|
+
s1 = s.reverse.scan(/.{1,3}/)
|
28
|
+
s2 = s1.reverse.map do |d|
|
29
|
+
d.reverse
|
30
|
+
end
|
31
|
+
# How many block
|
32
|
+
num_of_blocks = s2.size
|
33
|
+
# 5 is Trillion, 4 is Bilion, 3 is Milion, 2: Thousand, 1 Dong
|
34
|
+
words_first = s2.map do |e|
|
35
|
+
num_of_hundred(e.to_i)
|
36
|
+
end
|
37
|
+
words_string = num_to_words(words_first, num_of_blocks)
|
38
|
+
words_string = replace_with_special_word(words_string)
|
39
|
+
return words_string.lstrip.chop.capitalize+" "+char_currency
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.num_to_words(words_first, num_of_blocks)
|
43
|
+
s = ""
|
44
|
+
for i in 0...num_of_blocks
|
45
|
+
if words_first[i]!=''
|
46
|
+
s = s + words_first[i] + " "+ D[num_of_blocks-(i+1)]
|
47
|
+
s = s +" "
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
return s
|
52
|
+
end
|
53
|
+
|
54
|
+
def self.num_of_hundred(number)
|
55
|
+
s = ""
|
56
|
+
num_temp_mod100 = number%100
|
57
|
+
if num_temp_mod100==0
|
58
|
+
unless A[number/100]==''
|
59
|
+
s = s+ A[number/100] + " "+ E.first
|
60
|
+
end
|
61
|
+
return s
|
62
|
+
else
|
63
|
+
#So hang tram
|
64
|
+
tram = number/100
|
65
|
+
if tram>0
|
66
|
+
s = s+ A[tram] +" "+ E.first
|
67
|
+
end
|
68
|
+
num_temp_mod10 = num_temp_mod100%10
|
69
|
+
if (num_temp_mod10==0)
|
70
|
+
#so hang chuc
|
71
|
+
chuc = num_temp_mod100/10
|
72
|
+
s = s+" "+ C[chuc*10]
|
73
|
+
return s
|
74
|
+
else
|
75
|
+
chuc = num_temp_mod100/10
|
76
|
+
if chuc>0
|
77
|
+
s = s+" "+C[chuc*10]
|
78
|
+
end
|
79
|
+
donvi = num_temp_mod10
|
80
|
+
s = s +" "+ A[donvi]
|
81
|
+
if s.split(' ').size==3
|
82
|
+
SPECIAL.each do |k, v|
|
83
|
+
s.gsub!(k,v)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
return s
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
def self.replace_with_special_word(msg)
|
91
|
+
input = msg
|
92
|
+
SPECIAL_2.each do |k, v|
|
93
|
+
input.gsub!(k,v)
|
94
|
+
end
|
95
|
+
SPECIAL_3.each do |k, v|
|
96
|
+
input.gsub!(k,v)
|
97
|
+
end
|
98
|
+
return input
|
99
|
+
end
|
100
|
+
end
|
metadata
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: doc_tien
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tiến An - thien.su.bs
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-02-25 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.12'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.12'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
description: 'Thư viện hỗ trợ việc đọc tiền trong tiếng Việt. '
|
42
|
+
email:
|
43
|
+
- anvotien@gmail.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".gitignore"
|
49
|
+
- CODE_OF_CONDUCT.md
|
50
|
+
- Gemfile
|
51
|
+
- LICENSE.txt
|
52
|
+
- README.md
|
53
|
+
- Rakefile
|
54
|
+
- bin/console
|
55
|
+
- bin/setup
|
56
|
+
- doc_tien.gemspec
|
57
|
+
- lib/doc_tien.rb
|
58
|
+
- lib/doc_tien/version.rb
|
59
|
+
homepage: https://github.com/thiensubs/doc_tien
|
60
|
+
licenses:
|
61
|
+
- MIT
|
62
|
+
metadata:
|
63
|
+
allowed_push_host: https://rubygems.org
|
64
|
+
post_install_message:
|
65
|
+
rdoc_options: []
|
66
|
+
require_paths:
|
67
|
+
- lib
|
68
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
69
|
+
requirements:
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0'
|
73
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
requirements: []
|
79
|
+
rubyforge_project:
|
80
|
+
rubygems_version: 2.5.1
|
81
|
+
signing_key:
|
82
|
+
specification_version: 4
|
83
|
+
summary: '125000: Một trăm hai mươi lăm nghìn đồng. Thư viện hỗ trợ việc này'
|
84
|
+
test_files: []
|