chinese_money 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.travis.yml +7 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +10 -0
- data/Gemfile.lock +43 -0
- data/LICENSE.txt +21 -0
- data/README.md +43 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/chinese_money.gemspec +42 -0
- data/lib/chinese_money.rb +71 -0
- data/lib/chinese_money/version.rb +3 -0
- data/public/coverage/.last_run.json +5 -0
- data/public/coverage/.resultset.json +85 -0
- data/public/coverage/.resultset.json.lock +0 -0
- data/public/coverage/assets/0.10.2/application.css +799 -0
- data/public/coverage/assets/0.10.2/application.js +1707 -0
- data/public/coverage/assets/0.10.2/colorbox/border.png +0 -0
- data/public/coverage/assets/0.10.2/colorbox/controls.png +0 -0
- data/public/coverage/assets/0.10.2/colorbox/loading.gif +0 -0
- data/public/coverage/assets/0.10.2/colorbox/loading_background.png +0 -0
- data/public/coverage/assets/0.10.2/favicon_green.png +0 -0
- data/public/coverage/assets/0.10.2/favicon_red.png +0 -0
- data/public/coverage/assets/0.10.2/favicon_yellow.png +0 -0
- data/public/coverage/assets/0.10.2/loading.gif +0 -0
- data/public/coverage/assets/0.10.2/magnify.png +0 -0
- data/public/coverage/assets/0.10.2/smoothness/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
- data/public/coverage/assets/0.10.2/smoothness/images/ui-bg_flat_75_ffffff_40x100.png +0 -0
- data/public/coverage/assets/0.10.2/smoothness/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
- data/public/coverage/assets/0.10.2/smoothness/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
- data/public/coverage/assets/0.10.2/smoothness/images/ui-bg_glass_75_dadada_1x400.png +0 -0
- data/public/coverage/assets/0.10.2/smoothness/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
- data/public/coverage/assets/0.10.2/smoothness/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
- data/public/coverage/assets/0.10.2/smoothness/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
- data/public/coverage/assets/0.10.2/smoothness/images/ui-icons_222222_256x240.png +0 -0
- data/public/coverage/assets/0.10.2/smoothness/images/ui-icons_2e83ff_256x240.png +0 -0
- data/public/coverage/assets/0.10.2/smoothness/images/ui-icons_454545_256x240.png +0 -0
- data/public/coverage/assets/0.10.2/smoothness/images/ui-icons_888888_256x240.png +0 -0
- data/public/coverage/assets/0.10.2/smoothness/images/ui-icons_cd0a0a_256x240.png +0 -0
- data/public/coverage/index.html +853 -0
- metadata +131 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: b5ae05948b0de486f8c7f4921f89fbfc5af3efabb614dad135ba2dd53d75f305
|
4
|
+
data.tar.gz: 2c3236202b02cf74e9c2e3ab1dae2bfcd23914a8fa40dd762b6debc08ece41c5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1fdec867f431c8cbbdae81c48eda246ffca52e669d569c889429f6f79bd36caf9e31cf8198b12bcd4daecfc987e41d12e764c31167b19c5ef2f59b5525eccaa3
|
7
|
+
data.tar.gz: fdd46958e03570994ada76cc033077553e09f0b55ef912303ca8994fb661134ca7fd991b5f00133aa231b546573f481a2ba955807ea366bf708b5902a73217dc
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at pengmeizhou@126.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
chinese_money (1.0.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://gems.ruby-china.com/
|
8
|
+
specs:
|
9
|
+
diff-lcs (1.3)
|
10
|
+
docile (1.3.2)
|
11
|
+
json (2.2.0)
|
12
|
+
rake (10.5.0)
|
13
|
+
rspec (3.9.0)
|
14
|
+
rspec-core (~> 3.9.0)
|
15
|
+
rspec-expectations (~> 3.9.0)
|
16
|
+
rspec-mocks (~> 3.9.0)
|
17
|
+
rspec-core (3.9.0)
|
18
|
+
rspec-support (~> 3.9.0)
|
19
|
+
rspec-expectations (3.9.0)
|
20
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
21
|
+
rspec-support (~> 3.9.0)
|
22
|
+
rspec-mocks (3.9.0)
|
23
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
24
|
+
rspec-support (~> 3.9.0)
|
25
|
+
rspec-support (3.9.0)
|
26
|
+
simplecov (0.17.1)
|
27
|
+
docile (~> 1.1)
|
28
|
+
json (>= 1.8, < 3)
|
29
|
+
simplecov-html (~> 0.10.0)
|
30
|
+
simplecov-html (0.10.2)
|
31
|
+
|
32
|
+
PLATFORMS
|
33
|
+
ruby
|
34
|
+
|
35
|
+
DEPENDENCIES
|
36
|
+
bundler (~> 1.17)
|
37
|
+
chinese_money!
|
38
|
+
rake (~> 10.0)
|
39
|
+
rspec (~> 3.0)
|
40
|
+
simplecov
|
41
|
+
|
42
|
+
BUNDLED WITH
|
43
|
+
1.17.3
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2019 Peng Meizhou
|
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,43 @@
|
|
1
|
+
# ChineseMoney
|
2
|
+
|
3
|
+
To display money in Chinese characters format.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'chinese_money'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install chinese_money
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
ChineseMoney.show_money(0) -> 零圆整
|
24
|
+
ChineseMoney.show_money(250.01) -> 贰佰伍拾圆零壹分
|
25
|
+
ChineseMoney.show_money(2567890) -> 贰佰伍拾陆万柒仟捌佰玖拾圆整
|
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/PengMeizhou/chinese_money. 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
|
+
|
37
|
+
## License
|
38
|
+
|
39
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
40
|
+
|
41
|
+
## Code of Conduct
|
42
|
+
|
43
|
+
Everyone interacting in the ChineseMoney project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/PengMeizhou/chinese_money/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "chinese_money"
|
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__)
|
data/bin/setup
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "chinese_money/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "chinese_money"
|
8
|
+
spec.version = ChineseMoney::VERSION
|
9
|
+
spec.authors = ["Peng Meizhou"]
|
10
|
+
spec.email = ["pengmeizhou@126.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Change money display.}
|
13
|
+
spec.description = %q{To display money in Chinese Characters.}
|
14
|
+
spec.homepage = "https://github.com/PengMeizhou/chinese_money"
|
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
|
+
|
22
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
23
|
+
spec.metadata["source_code_uri"] = "https://github.com/PengMeizhou/chinese_money"
|
24
|
+
spec.metadata["changelog_uri"] = "https://github.com/PengMeizhou/chinese_money/blob/master/README.md"
|
25
|
+
else
|
26
|
+
raise "RubyGems 2.0 or newer is required to protect against " \
|
27
|
+
"public gem pushes."
|
28
|
+
end
|
29
|
+
|
30
|
+
# Specify which files should be added to the gem when it is released.
|
31
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
32
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
33
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
34
|
+
end
|
35
|
+
spec.bindir = "exe"
|
36
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
37
|
+
spec.require_paths = ["lib"]
|
38
|
+
|
39
|
+
spec.add_development_dependency "bundler", "~> 1.17"
|
40
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
41
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
42
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require 'chinese_money/version'
|
2
|
+
|
3
|
+
# Display Chinese money
|
4
|
+
module ChineseMoney
|
5
|
+
class Error < StandardError; end
|
6
|
+
# main method
|
7
|
+
def self.show_money(total_money)
|
8
|
+
cn_upper_number =%w[零 壹 贰 叁 肆 伍 陆 柒 捌 玖]
|
9
|
+
cn_upper_monetray_unit = %w[分 角 圆 拾 佰 仟 万 拾 佰 仟 亿 拾 佰 仟 兆 拾 佰 仟]
|
10
|
+
cn_full = '整'
|
11
|
+
cn_negative = '负'
|
12
|
+
money_precision = 2
|
13
|
+
cn_zeor_full = "零圆#{cn_full}"
|
14
|
+
is_zero = false
|
15
|
+
zero_size = 0
|
16
|
+
num_index = 0
|
17
|
+
num_unit = 0
|
18
|
+
change_result = []
|
19
|
+
my_total_price = total_money
|
20
|
+
|
21
|
+
# Too long too big/cannot support
|
22
|
+
return '只支持总长度不超过17位的数字。' if my_total_price.to_i > 100000000000000
|
23
|
+
|
24
|
+
# For zero
|
25
|
+
return cn_zeor_full if my_total_price.zero?
|
26
|
+
|
27
|
+
# For round
|
28
|
+
my_number = my_total_price.round(money_precision) * 100
|
29
|
+
scale = my_number % 100
|
30
|
+
|
31
|
+
if scale.to_f.zero?
|
32
|
+
num_index = 2
|
33
|
+
my_number /= 100
|
34
|
+
is_zero = true
|
35
|
+
end
|
36
|
+
|
37
|
+
if ((scale > 0) && (!(scale % 10 > 0)))
|
38
|
+
num_index = 1
|
39
|
+
my_number /= 10
|
40
|
+
is_zero = true
|
41
|
+
end
|
42
|
+
|
43
|
+
loop do
|
44
|
+
break if my_number <= 0
|
45
|
+
|
46
|
+
num_unit = (my_number % 10).to_i
|
47
|
+
if (num_unit > 0)
|
48
|
+
change_result.prepend(cn_upper_monetray_unit[6]) if ((num_index == 9) && (zero_size >= 3))
|
49
|
+
change_result.prepend(cn_upper_monetray_unit[10]) if ((num_index == 13) && (zero_size >= 3))
|
50
|
+
change_result.prepend(cn_upper_monetray_unit[num_index])
|
51
|
+
change_result.prepend(cn_upper_number[num_unit])
|
52
|
+
is_zero = false
|
53
|
+
zero_size = 0
|
54
|
+
else
|
55
|
+
zero_size += 1
|
56
|
+
change_result.prepend(cn_upper_number[num_unit]) unless is_zero
|
57
|
+
if num_index == 2
|
58
|
+
change_result.prepend(cn_upper_monetray_unit[num_index]) if (my_number > 0)
|
59
|
+
elsif (((num_index - 2) % 4 == 0) && (my_number % 1000 > 0))
|
60
|
+
change_result.prepend(cn_upper_monetray_unit[num_index])
|
61
|
+
end
|
62
|
+
is_zero = true
|
63
|
+
end
|
64
|
+
my_number = (my_number / 10).to_i
|
65
|
+
num_index += 1
|
66
|
+
end
|
67
|
+
change_result.prepend(cn_negative) if my_total_price < 0
|
68
|
+
change_result.append(cn_full) unless scale > 0
|
69
|
+
change_result.join
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
{
|
2
|
+
"RSpec": {
|
3
|
+
"coverage": {
|
4
|
+
"/home/pengmz/work/self_learning/chinese_money/lib/chinese_money.rb": [
|
5
|
+
1,
|
6
|
+
null,
|
7
|
+
null,
|
8
|
+
1,
|
9
|
+
1,
|
10
|
+
null,
|
11
|
+
1,
|
12
|
+
15,
|
13
|
+
15,
|
14
|
+
15,
|
15
|
+
15,
|
16
|
+
15,
|
17
|
+
15,
|
18
|
+
15,
|
19
|
+
15,
|
20
|
+
15,
|
21
|
+
15,
|
22
|
+
15,
|
23
|
+
15,
|
24
|
+
null,
|
25
|
+
null,
|
26
|
+
15,
|
27
|
+
null,
|
28
|
+
null,
|
29
|
+
13,
|
30
|
+
null,
|
31
|
+
null,
|
32
|
+
12,
|
33
|
+
12,
|
34
|
+
null,
|
35
|
+
12,
|
36
|
+
9,
|
37
|
+
9,
|
38
|
+
9,
|
39
|
+
null,
|
40
|
+
null,
|
41
|
+
12,
|
42
|
+
1,
|
43
|
+
1,
|
44
|
+
1,
|
45
|
+
null,
|
46
|
+
null,
|
47
|
+
12,
|
48
|
+
73,
|
49
|
+
null,
|
50
|
+
61,
|
51
|
+
61,
|
52
|
+
27,
|
53
|
+
27,
|
54
|
+
27,
|
55
|
+
27,
|
56
|
+
27,
|
57
|
+
27,
|
58
|
+
null,
|
59
|
+
34,
|
60
|
+
34,
|
61
|
+
34,
|
62
|
+
10,
|
63
|
+
24,
|
64
|
+
2,
|
65
|
+
null,
|
66
|
+
34,
|
67
|
+
null,
|
68
|
+
61,
|
69
|
+
61,
|
70
|
+
null,
|
71
|
+
12,
|
72
|
+
12,
|
73
|
+
12,
|
74
|
+
null,
|
75
|
+
null
|
76
|
+
],
|
77
|
+
"/home/pengmz/work/self_learning/chinese_money/lib/chinese_money/version.rb": [
|
78
|
+
0,
|
79
|
+
0,
|
80
|
+
0
|
81
|
+
]
|
82
|
+
},
|
83
|
+
"timestamp": 1575967773
|
84
|
+
}
|
85
|
+
}
|