tipgen 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: 944c645871b58de59921a80c18196d45f0a465f2645da4d6b9dbe88efc473a6d
4
+ data.tar.gz: 50882203ee880a1d1dd39f848c689f66df0ac9fe099611effedfdf4bff42dec1
5
+ SHA512:
6
+ metadata.gz: 8dff11ecb57fc0e242499bccaa23d28dee80eb62e1e3787e76ed81193846a57a03132884488a4bdebe0528a4038f5d8aa91d477066514227d825b2d93ada5ec5
7
+ data.tar.gz: a9ebae919e207bf99be8ab8871da9811a6e57796fbcfa5e9a0ce9c02bc278942f773d32048db3fe4b989e67c6e16af64f5174d49e282e36c1fd414c144bd71e7
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ # rspec failure tracking
10
+ .rspec_status
11
+ *.gem
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.3
5
+ before_install: gem install bundler -v 1.16.2
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in tipgen.gemspec
4
+ gemspec
@@ -0,0 +1,35 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ tipgen (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ diff-lcs (1.3)
10
+ rake (10.5.0)
11
+ rspec (3.8.0)
12
+ rspec-core (~> 3.8.0)
13
+ rspec-expectations (~> 3.8.0)
14
+ rspec-mocks (~> 3.8.0)
15
+ rspec-core (3.8.0)
16
+ rspec-support (~> 3.8.0)
17
+ rspec-expectations (3.8.1)
18
+ diff-lcs (>= 1.2.0, < 2.0)
19
+ rspec-support (~> 3.8.0)
20
+ rspec-mocks (3.8.0)
21
+ diff-lcs (>= 1.2.0, < 2.0)
22
+ rspec-support (~> 3.8.0)
23
+ rspec-support (3.8.0)
24
+
25
+ PLATFORMS
26
+ ruby
27
+
28
+ DEPENDENCIES
29
+ bundler (~> 1.16)
30
+ rake (~> 10.0)
31
+ rspec (~> 3.0)
32
+ tipgen!
33
+
34
+ BUNDLED WITH
35
+ 1.16.2
@@ -0,0 +1,35 @@
1
+ # Tipgen
2
+
3
+ ## Installation
4
+
5
+ Add this line to your application's Gemfile:
6
+
7
+ ```ruby
8
+ gem 'tipgen'
9
+ ```
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install tipgen
18
+
19
+ ## Usage
20
+
21
+ ```ruby
22
+ Tipgen::Builder.new(total: 100, gratuity: '23.5').generate # 123.5
23
+ Tipgen::Builder.new(total: 100, gratuity: 'high').generate # 125.0
24
+ Tipgen::Builder.new(total: 100, gratuity: 'LOW').generate # 115.0
25
+ Tipgen::Builder.new(total: 100, gratuity: 20).generate # 120.0
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/<github username>/tipgen.
@@ -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 "tipgen"
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
data/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "tipgen"
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,40 @@
1
+ require "tipgen/version"
2
+
3
+ class String
4
+ def integer?
5
+ return true if self =~ /^[1-9]\d*(\.\d+)?$/
6
+ false
7
+ end
8
+ end
9
+
10
+ module Tipgen
11
+
12
+ class Builder
13
+ def initialize total:, gratuity:
14
+ @total = total
15
+ @gratuity = gratuity
16
+ end
17
+
18
+ def generate
19
+ return calculation if number_based?
20
+ string_based
21
+ end
22
+
23
+ def number_based?
24
+ (@gratuity.is_a? Numeric) || (@gratuity.integer?)
25
+ end
26
+
27
+ def string_based
28
+ case @gratuity.downcase
29
+ when 'high' then calculation 25
30
+ when 'standard' then calculation 18
31
+ when 'low' then calculation 15
32
+ end
33
+ end
34
+
35
+ def calculation gratuity = @gratuity
36
+ @total += @total * (gratuity.to_f / 100)
37
+ end
38
+ end
39
+
40
+ end
@@ -0,0 +1,3 @@
1
+ module Tipgen
2
+ VERSION = "0.1.0"
3
+ end
data/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,14 @@
1
+ require "bundler/setup"
2
+ require "tipgen"
3
+
4
+ RSpec.configure do |config|
5
+ # Enable flags like --only-failures and --next-failure
6
+ config.example_status_persistence_file_path = ".rspec_status"
7
+
8
+ # Disable RSpec exposing methods globally on `Module` and `main`
9
+ config.disable_monkey_patching!
10
+
11
+ config.expect_with :rspec do |c|
12
+ c.syntax = :expect
13
+ end
14
+ end
@@ -0,0 +1,26 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "tipgen/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "tipgen"
8
+ spec.version = Tipgen::VERSION
9
+ spec.authors = ["Nancy Do"]
10
+ spec.email = ["nancydo7@gmail.com"]
11
+
12
+ spec.summary = %q{Generate tip amount based on inputs.}
13
+ spec.homepage = "https://github.com/bunnyd/tipgen"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
17
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ end
19
+ spec.bindir = "exe"
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.16"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "rspec", "~> 3.0"
26
+ end
@@ -0,0 +1,25 @@
1
+ require "spec_helper"
2
+
3
+ RSpec.describe Tipgen do
4
+ it "has a version number" do
5
+ expect(Tipgen::VERSION).not_to be nil
6
+ end
7
+
8
+ it 'Accurately generates a tip given string or integer input' do
9
+ test_1 = Tipgen::Builder.new(total: 100, gratuity: '23.5').generate
10
+ test_2 = Tipgen::Builder.new(total: 100, gratuity: 'high').generate
11
+ test_3 = Tipgen::Builder.new(total: 100, gratuity: 'LOW').generate
12
+ test_4 = Tipgen::Builder.new(total: 100, gratuity: 'standard').generate
13
+ test_5 = Tipgen::Builder.new(total: 100, gratuity: '18').generate
14
+ test_6 = Tipgen::Builder.new(total: 100, gratuity: 20).generate
15
+ test_7 = Tipgen::Builder.new(total: 100, gratuity: 0).generate
16
+
17
+ expect(test_1).to eq(123.5)
18
+ expect(test_2).to eq(125.0)
19
+ expect(test_3).to eq(115.0)
20
+ expect(test_4).to eq(118.0)
21
+ expect(test_5).to eq(118.0)
22
+ expect(test_6).to eq(120.0)
23
+ expect(test_7).to eq(100.0)
24
+ end
25
+ end
metadata ADDED
@@ -0,0 +1,102 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tipgen
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Nancy Do
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-08-29 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.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
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
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ description:
56
+ email:
57
+ - nancydo7@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".rspec"
64
+ - ".travis.yml"
65
+ - Gemfile
66
+ - Gemfile.lock
67
+ - README.md
68
+ - Rakefile
69
+ - bin/console
70
+ - bin/setup
71
+ - console
72
+ - lib/tipgen.rb
73
+ - lib/tipgen/version.rb
74
+ - setup
75
+ - spec_helper.rb
76
+ - tipgen.gemspec
77
+ - tipgen_spec.rb
78
+ homepage: https://github.com/bunnyd/tipgen
79
+ licenses:
80
+ - MIT
81
+ metadata: {}
82
+ post_install_message:
83
+ rdoc_options: []
84
+ require_paths:
85
+ - lib
86
+ required_ruby_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ requirements: []
97
+ rubyforge_project:
98
+ rubygems_version: 2.7.7
99
+ signing_key:
100
+ specification_version: 4
101
+ summary: Generate tip amount based on inputs.
102
+ test_files: []