vietnamese_number 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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 617b7da65e2b794710ea98d21f549ebc7478aea20358a707406a88ffb08291af
4
+ data.tar.gz: 49e496b27bbb37d3798c7ea8fc6df79333017a3c98ea5fc77a2a2c4e47860638
5
+ SHA512:
6
+ metadata.gz: ce2de8eeef66b900635cdcd918889b9baa2e67c5c38be576414ed58d6ff9b2ccdd1c7365cf787c98b302d6d2ab9cd8b7390e2b441c3a61453676922be86f2847
7
+ data.tar.gz: bd2bc0b105b827e14d57ed5177b4c9eb256f3263a09bee75663cba94da8188a47ce04e39ce6ffb09bcaa066ac580ac38633815646fd1fdb723dbe926fc313d57
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2024-04-09
4
+
5
+ - Initial release
data/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # VietnameseNumber
2
+
3
+ TODO: Delete this and the text below, and describe your gem
4
+
5
+ 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/vietnamese_number`. To experiment with that code, run `bin/console` for an interactive prompt.
6
+
7
+ ## Installation
8
+
9
+ TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
10
+
11
+ Install the gem and add to the application's Gemfile by executing:
12
+
13
+ $ bundle add UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
14
+
15
+ If bundler is not being used to manage dependencies, install the gem by executing:
16
+
17
+ $ gem install UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Development
24
+
25
+ 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.
26
+
27
+ 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 the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
28
+
29
+ ## Contributing
30
+
31
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/vietnamese_number. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/vietnamese_number/blob/main/CODE_OF_CONDUCT.md).
32
+
33
+ ## Code of Conduct
34
+
35
+ Everyone interacting in the VietnameseNumber project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/vietnamese_number/blob/main/CODE_OF_CONDUCT.md).
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "vietnamese_number"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -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,56 @@
1
+ # frozen_string_literal: true
2
+
3
+ module VietnameseNumber
4
+ # The calculate utils
5
+ module Utils
6
+ def self.number_in_words(number)
7
+ [].tap do |result|
8
+ arr_number = number.to_i.to_s.chars.to_a.reverse.each_slice(3).map(&:join)
9
+ arr_number.each_with_index do |value, index|
10
+ result << "#{separator_name(index * 3)}" unless index.zero?
11
+
12
+ value.each_char.with_index do |char, index|
13
+ next if index.zero? && char == '0'
14
+
15
+ if index.zero? && char == '1'
16
+ result << 'mốt'
17
+ elsif index == 1 && char == '1'
18
+ result << 'mười'
19
+ else
20
+ result << "#{separator_name(index)}" if separator_name(index).present?
21
+ result << "#{convert_to_name(char)}"
22
+ end
23
+ end
24
+ end
25
+ end.reverse.join(' ')
26
+ end
27
+
28
+ def self.separator_name(index)
29
+ hash = {
30
+ 1 => 'mươi',
31
+ 2 => 'trăm',
32
+ 3 => 'ngàn',
33
+ 6 => 'triệu',
34
+ 9 => 'tỷ',
35
+ 12 => 'ngàn tỷ'
36
+ }
37
+ hash[index]
38
+ end
39
+
40
+ def self.convert_to_name(num)
41
+ hash = {
42
+ '0' => 'không',
43
+ '1' => 'một',
44
+ '2' => 'hai',
45
+ '3' => 'ba',
46
+ '4' => 'bốn',
47
+ '5' => 'năm',
48
+ '6' => 'sáu',
49
+ '7' => 'bảy',
50
+ '8' => 'tám',
51
+ '9' => 'chín'
52
+ }
53
+ hash[num.to_s]
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module VietnameseNumber
4
+ VERSION = "0.1.0"
5
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "vietnamese_number/version"
4
+ require_relative 'vietnamese_number/utils'
5
+
6
+ # The Vietnamese Number
7
+ module VietnameseNumber
8
+ class Error < StandardError; end
9
+
10
+ def self.number_in_words(number)
11
+ Utils.number_in_words(number)
12
+ end
13
+ end
metadata ADDED
@@ -0,0 +1,51 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vietnamese_number
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Thanh
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2024-04-09 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: The library provides methods to convert numbers into Vietnamese.
14
+ email:
15
+ - thanhbk150@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - CHANGELOG.md
21
+ - README.md
22
+ - bin/console
23
+ - bin/setup
24
+ - lib/vietnamese_number.rb
25
+ - lib/vietnamese_number/utils.rb
26
+ - lib/vietnamese_number/version.rb
27
+ homepage: https://github.com/thanhbk150/vietnamese_number
28
+ licenses: []
29
+ metadata:
30
+ allowed_push_host: https://rubygems.org/
31
+ homepage_uri: https://github.com/thanhbk150/vietnamese_number
32
+ post_install_message:
33
+ rdoc_options: []
34
+ require_paths:
35
+ - lib
36
+ required_ruby_version: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 2.6.0
41
+ required_rubygems_version: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ requirements: []
47
+ rubygems_version: 3.2.33
48
+ signing_key:
49
+ specification_version: 4
50
+ summary: The library provides methods to convert numbers into Vietnamese.
51
+ test_files: []