numstr 0.1.1

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: d0a8064daa17a615dbc7f3b52da0dd5f40bcc8dbd010ee9318b7f7810c33b1e2
4
+ data.tar.gz: 9feb0b244836a662da31527c59c4be4fb7fdf525e4eca17af332355f7e6406d7
5
+ SHA512:
6
+ metadata.gz: afc906098cdcdca14af188eeffe0edeac6e0ba593160a5e36bf51c275db9e66aa94b92c38f7a9bd6ae84db2e8f67d7e38830b7fdf5eca2913268c8a51f82ed32
7
+ data.tar.gz: 5ce5d9c938cdb316ae4af1d1547b8f7c440de134d3cda381ba46984cbce188ef2935124722c4698e7ecb060bf5f914cc3d472c909ac77dcad44817daabaa0362
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ *.gem
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ ---
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.7.0
6
+ before_install: gem install bundler -v 2.1.2
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in numstr.gemspec
4
+ gemspec
5
+
6
+ gem "rake", "~> 12.0"
7
+ gem "rspec", "~> 3.0"
data/Gemfile.lock ADDED
@@ -0,0 +1,34 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ numstr (0.1.1)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ diff-lcs (1.3)
10
+ rake (12.3.3)
11
+ rspec (3.9.0)
12
+ rspec-core (~> 3.9.0)
13
+ rspec-expectations (~> 3.9.0)
14
+ rspec-mocks (~> 3.9.0)
15
+ rspec-core (3.9.1)
16
+ rspec-support (~> 3.9.1)
17
+ rspec-expectations (3.9.1)
18
+ diff-lcs (>= 1.2.0, < 2.0)
19
+ rspec-support (~> 3.9.0)
20
+ rspec-mocks (3.9.1)
21
+ diff-lcs (>= 1.2.0, < 2.0)
22
+ rspec-support (~> 3.9.0)
23
+ rspec-support (3.9.2)
24
+
25
+ PLATFORMS
26
+ ruby
27
+
28
+ DEPENDENCIES
29
+ numstr!
30
+ rake (~> 12.0)
31
+ rspec (~> 3.0)
32
+
33
+ BUNDLED WITH
34
+ 2.1.2
data/README.md ADDED
@@ -0,0 +1,50 @@
1
+ # Numstr
2
+
3
+ It's Numstr. And it's useless.
4
+
5
+ Made as an educational gem, this tiny little bugger gets a number and returns its us-english version.
6
+
7
+ That's all, please and thank you very much.
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'numstr'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ $ bundle install
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install numstr
24
+
25
+ ## Usage
26
+
27
+ Run:
28
+ ```
29
+ $ irb
30
+ 2.7.0 :001 > require 'Numstr'
31
+ ```
32
+
33
+ You can play then or you can hit ENTER, get out of the loop and use Numstr as follows:
34
+ ```ruby
35
+ Numstr.to_str(101) # => 'one hundred one'
36
+ Numstr.to_str(-999999) # => 'minus nine hundred ninety nine thousand nine hundred ninety nine'
37
+ Numstr.to_str( 0) # => 'zero, null, nil, nada, zip, goose egg'
38
+ Numstr.to_str("hi!") # => "C'mon! 'hi!' is not a number!"
39
+ ```
40
+
41
+ When you finally get bored, don't forget to uninstall the gem. Seriously, why on Earth would you need it?
42
+
43
+ ## Development
44
+
45
+ Nada.
46
+
47
+ ## Contributing
48
+
49
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/numstr.
50
+
data/Rakefile ADDED
@@ -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
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "numstr"
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,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
data/lib/numstr.rb ADDED
@@ -0,0 +1,105 @@
1
+ require "numstr/version"
2
+
3
+ module Numstr
4
+ def self.to_str(num)
5
+ # return "C'mon! '#{num}' is not a number!" unless num.is_a? Integer
6
+ return 'zero, null, nil, nada, zip, goose egg' if num.zero?
7
+
8
+ if num.negative?
9
+ negative = true
10
+ num = num.abs
11
+ end
12
+
13
+ num_string = ''
14
+
15
+ ones_array = %w[one two three four five six seven eight nine]
16
+ tens_array = %w[ten twenty thirty forty fifty sixty seventy eighty ninety]
17
+ teenagers_array = %w[eleven twelve thirteen fourteen fifteen sixteen seventeen eighteen nineteen]
18
+
19
+ zillions = [
20
+ ['hundred', 2],
21
+ ['thousand', 3],
22
+ ['million', 6],
23
+ ['billion', 9],
24
+ ['trillion', 12],
25
+ ['quadrillion', 15],
26
+ ['quintillion', 18],
27
+ ['sextillion', 21],
28
+ ['septillion', 24],
29
+ ['octillion', 27],
30
+ ['nonillion', 30],
31
+ ['decillion', 33],
32
+ ['undecillion', 36],
33
+ ['duodecillion', 39],
34
+ ['tredecillion', 42],
35
+ ['quattuordecillion', 45],
36
+ ['quindecillion', 48],
37
+ ['sexdecillion', 51],
38
+ ['septendecillion', 54],
39
+ ['octodecillion', 57],
40
+ ['novemdecillion', 60],
41
+ ['vigintillion', 63],
42
+ ['googol', 100]
43
+ ]
44
+
45
+ left = num
46
+
47
+ if negative
48
+ num_string = 'minus' + ' '
49
+ end
50
+
51
+ until zillions.empty?
52
+ zill = zillions.pop
53
+ zill_name = zill[0]
54
+ zill_base = 10**zill[1]
55
+
56
+ write = left / zill_base
57
+ left -= write * zill_base
58
+
59
+ if write > 0
60
+ prefix = to_str write
61
+ num_string += prefix + ' ' + zill_name
62
+
63
+ num_string += ' ' if left.positive?
64
+ end
65
+ end
66
+
67
+ write = left / 10
68
+ left -= write * 10
69
+
70
+ if write > 0
71
+ if write == 1 && left > 0
72
+ num_string += teenagers_array[left -1]
73
+ left = 0
74
+ else
75
+ num_string += tens_array[write - 1]
76
+ end
77
+ num_string += ' ' if left.positive?
78
+ end
79
+
80
+ write = left
81
+ left = 0
82
+
83
+ if write > 0
84
+ num_string += ones_array[write - 1]
85
+ end
86
+ num_string
87
+ end
88
+ end
89
+
90
+ puts 'Hey! Put a whole number without breaks and EMBRACE THE POWER of this gem!!!11'
91
+ puts "Want to get out of here? Don't put anything and hit the ENTER button, please and thank you."
92
+
93
+ loop do
94
+ input = gets.chomp
95
+
96
+ if input == ''
97
+ puts 'd-_-b'
98
+ break
99
+ else
100
+ next puts "C'mon! '#{input}' is not a number!" unless input =~ /\A[+-]?\d+(\.\d+)?\z/
101
+ puts Numstr.to_str input.to_i
102
+ end
103
+ end
104
+
105
+
@@ -0,0 +1,3 @@
1
+ module Numstr
2
+ VERSION = "0.1.1"
3
+ end
data/numstr.gemspec ADDED
@@ -0,0 +1,27 @@
1
+ require_relative 'lib/numstr/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "numstr"
5
+ spec.version = Numstr::VERSION
6
+ spec.authors = ["vladveterok"]
7
+ spec.email = ["vl.berezhnoi@gmail.com"]
8
+
9
+ spec.summary = %q{Returns a string with the english version of a number. You say '5', I say 'five'!}
10
+ spec.homepage = "https://github.com/vladveterok/numstr"
11
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
12
+
13
+ # spec.metadata["allowed_push_host"] = "http://mygemserver.com"
14
+
15
+ spec.metadata["homepage_uri"] = spec.homepage
16
+ spec.metadata["source_code_uri"] = "https://github.com/vladveterok/numstr"
17
+ spec.metadata["changelog_uri"] = "https://github.com/vladveterok/numstr"
18
+
19
+ # Specify which files should be added to the gem when it is released.
20
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
21
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
22
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
23
+ end
24
+ spec.bindir = "exe"
25
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
26
+ spec.require_paths = ["lib"]
27
+ end
metadata ADDED
@@ -0,0 +1,58 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: numstr
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - vladveterok
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-04-19 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description:
14
+ email:
15
+ - vl.berezhnoi@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - ".gitignore"
21
+ - ".rspec"
22
+ - ".travis.yml"
23
+ - Gemfile
24
+ - Gemfile.lock
25
+ - README.md
26
+ - Rakefile
27
+ - bin/console
28
+ - bin/setup
29
+ - lib/numstr.rb
30
+ - lib/numstr/version.rb
31
+ - numstr.gemspec
32
+ homepage: https://github.com/vladveterok/numstr
33
+ licenses: []
34
+ metadata:
35
+ homepage_uri: https://github.com/vladveterok/numstr
36
+ source_code_uri: https://github.com/vladveterok/numstr
37
+ changelog_uri: https://github.com/vladveterok/numstr
38
+ post_install_message:
39
+ rdoc_options: []
40
+ require_paths:
41
+ - lib
42
+ required_ruby_version: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: 2.3.0
47
+ required_rubygems_version: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ version: '0'
52
+ requirements: []
53
+ rubygems_version: 3.1.2
54
+ signing_key:
55
+ specification_version: 4
56
+ summary: Returns a string with the english version of a number. You say '5', I say
57
+ 'five'!
58
+ test_files: []