salary_calc 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ NGY2MjYyMjAxOWE1M2UxYjNlYjJmZTM3YzgzMDQ4NTE3MGY3NTVkZQ==
5
+ data.tar.gz: !binary |-
6
+ Y2M1ZDVjMDY0NmQzYTA2ZjVhZmQxZTdhZmQ0NGI2ZGJlYzQyMTkxNg==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ NDJmN2U4MWMyYjU1ZTNkZmY4MjYzYTNmMmQxMmFkY2Y0NmMxZTY1OWMwNTE4
10
+ Y2Q3NzM0MzViZWFiYmVjNGIxMGZmZmY3Y2ZhZjZhMTc4NmRiMjAyODQ3OTRm
11
+ ZTM0ZjY4YjJhMWQwYWFlNDZhMTJjZTA1Nzk2YzkzZDIzYzQ0ODk=
12
+ data.tar.gz: !binary |-
13
+ MjFmNTgzMzdlYTNlNzNkMTUzYWM3ODFmYjJlMTViNDE4NGJkOTBiNWFhNTAy
14
+ M2UwZDc4MzI2N2VlYzE0NWM1ODA2YTBjNGVhOTUxMjZhMGE5MmUwYmIwMmI5
15
+ NWE4ZmMxNzU3MmY3YzJkNDllMzVlOGQ0YTg1M2Y2MTQyZDExNmM=
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ vendor/bundle
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in salary_calc.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Adrian Perez
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,64 @@
1
+ # SalaryCalc
2
+
3
+ A very simple salary calculator.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'salary_calc'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install salary_calc
18
+
19
+ ## Usage
20
+
21
+ Calculating based on an hourly rate, and default 8 billable hours:
22
+
23
+ ```ruby
24
+ require 'salary_calc'
25
+
26
+ calculator = SalaryCalc::Calculator.new(15)
27
+ calculator.to_daily #=> 120
28
+ calculator.to_weekly #=> 600
29
+ calculator.to_monthly #=> 2400
30
+ calculator.to_yearly #=> 28800
31
+ ```
32
+
33
+ Specify billable hours:
34
+
35
+ ```ruby
36
+ calculator = SalaryCalc::Calculator.new(15, 6)
37
+ calculator.to_daily = 90
38
+ ```
39
+
40
+ Getting the hourly rate for a specific amount different that hourly rate:
41
+
42
+ ```ruby
43
+ calculator = SalaryCalc::Calculator.new(15)
44
+ calculator.from_yearly(2500)
45
+ ```
46
+
47
+ Getting and setting the hourly rate to amount inside the calculator:
48
+
49
+ ```ruby
50
+ calculator = SalaryCalc::Calculator.new(2400)
51
+ calculator.amount #=> 2400
52
+ calculator.from_monthly!
53
+ calculator.amount #=> 15
54
+ ```
55
+
56
+ Take a look at the tests for more use cases. ;)
57
+
58
+ ## Contributing
59
+
60
+ 1. Fork it
61
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
62
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
63
+ 4. Push to the branch (`git push origin my-new-feature`)
64
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,5 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new('spec')
5
+ task :default => :spec
@@ -0,0 +1,20 @@
1
+ require "salary_calc/version"
2
+ require "salary_calc/conversions/to_hourly"
3
+ require "salary_calc/conversions/from_hourly"
4
+
5
+ module SalaryCalc
6
+ class Calculator
7
+ include Conversions::FromHourly
8
+ include Conversions::ToHourly
9
+ attr_accessor :amount, :billable_hours
10
+
11
+ def initialize(amount, billable_hours = 8)
12
+ @amount = amount
13
+ @billable_hours = billable_hours
14
+ end
15
+
16
+ def to_hourly
17
+ amount
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,19 @@
1
+ module SalaryCalc::Conversions
2
+ module FromHourly
3
+ def to_yearly
4
+ to_monthly * 12
5
+ end
6
+
7
+ def to_monthly
8
+ to_weekly * 4
9
+ end
10
+
11
+ def to_weekly
12
+ to_daily * 5
13
+ end
14
+
15
+ def to_daily
16
+ billable_hours * amount
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,25 @@
1
+ module SalaryCalc::Conversions
2
+ module ToHourly
3
+ def from_yearly(yearly)
4
+ from_monthly(yearly.to_f / 12)
5
+ end
6
+
7
+ def from_monthly(monthly)
8
+ from_weekly(monthly.to_f / 4)
9
+ end
10
+
11
+ def from_weekly(weekly)
12
+ from_daily(weekly.to_f / 5)
13
+ end
14
+
15
+ def from_daily(daily)
16
+ daily / billable_hours.to_f
17
+ end
18
+
19
+ [:yearly, :monthly, :weekly, :daily].each do |period|
20
+ define_method("from_#{period}!") do |amount_to_calculate = self.amount|
21
+ self.amount = send("from_#{period}", amount_to_calculate)
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,3 @@
1
+ module SalaryCalc
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'salary_calc/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "salary_calc"
8
+ spec.version = SalaryCalc::VERSION
9
+ spec.authors = ["Adrian Perez"]
10
+ spec.email = ["adrianperez.deb@gmail.com"]
11
+ spec.description = %q{A very simple salary calculator}
12
+ spec.summary = spec.description
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec", "~> 2.14.1"
24
+ end
@@ -0,0 +1,85 @@
1
+ require 'spec_helper'
2
+ require 'salary_calc'
3
+
4
+ module SalaryCalc
5
+ describe Calculator do
6
+ context "initialization" do
7
+ it "initializes and exposes amount and billable hours" do
8
+ calculator = described_class.new(2500, 7)
9
+ expect(calculator.amount).to be
10
+ expect(calculator.billable_hours).to be
11
+ end
12
+
13
+ it "defaults to 8 billable hours" do
14
+ expect(described_class.new(1).billable_hours).to eq(8)
15
+ end
16
+ end
17
+
18
+ context "calculations" do
19
+ let(:amount) { 10 } # the easiest number for math
20
+ let(:calculator) { described_class.new(amount) }
21
+
22
+ describe "#to_yearly" do
23
+ it "calculates the yearly salary from an hourly rate" do
24
+ expect(calculator.to_yearly).to eq(19_200)
25
+ end
26
+ end
27
+
28
+ describe "#to_monthly" do
29
+ it "calculates the monthly salary from an hourly rate" do
30
+ expect(calculator.to_monthly).to eq(1_600)
31
+ end
32
+ end
33
+
34
+ describe "#to_weekly" do
35
+ it "calculates teh weekly salary from an hourly rate" do
36
+ expect(calculator.to_weekly).to eq(400)
37
+ end
38
+ end
39
+
40
+ describe "#to_daily" do
41
+ it "calculates the daily salary for an hourly rate" do
42
+ expect(calculator.to_daily).to eq(80)
43
+ end
44
+ end
45
+
46
+ describe "#from_yearly" do
47
+ it "returns the hourly rate from a yearly salary" do
48
+ expect(calculator.from_yearly(19_200)).to eq(10)
49
+ end
50
+ end
51
+
52
+ describe "#from_monthly" do
53
+ it "returns the hourly rate from a monthly salary" do
54
+ expect(calculator.from_monthly(1_600)).to eq(10)
55
+ end
56
+ end
57
+
58
+ describe "#from_weekly" do
59
+ it "returns the hourly rate from a weekly salary" do
60
+ expect(calculator.from_weekly(400)).to eq(10)
61
+ end
62
+ end
63
+
64
+ describe "#from_daily" do
65
+ it "returns the hourly rate from a daily salary" do
66
+ expect(calculator.from_daily(80)).to eq(10)
67
+ end
68
+ end
69
+
70
+ describe "#from_*_!" do
71
+ it "modifies the calculator's amount to reflect hourly rate" do
72
+ expect(calculator.amount).to eq(10)
73
+ calculator.from_monthly!(2400)
74
+ expect(calculator.amount).to eq(15)
75
+ end
76
+
77
+ it "uses the amount from the calculator if none specified" do
78
+ calculator.amount = 2400
79
+ calculator.from_monthly!
80
+ expect(calculator.amount).to eq(15)
81
+ end
82
+ end
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,17 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # Require this file using `require "spec_helper"` to ensure that it is only
4
+ # loaded once.
5
+ #
6
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
7
+ RSpec.configure do |config|
8
+ config.treat_symbols_as_metadata_keys_with_true_values = true
9
+ config.run_all_when_everything_filtered = true
10
+ #config.filter_run :focus
11
+
12
+ # Run specs in random order to surface order dependencies. If you find an
13
+ # order dependency and want to debug it, you can fix the order by providing
14
+ # the seed, which is printed after each run.
15
+ # --seed 1234
16
+ config.order = 'random'
17
+ end
metadata ADDED
@@ -0,0 +1,102 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: salary_calc
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Adrian Perez
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-09-30 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.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '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: 2.14.1
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 2.14.1
55
+ description: A very simple salary calculator
56
+ email:
57
+ - adrianperez.deb@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - .gitignore
63
+ - .rspec
64
+ - Gemfile
65
+ - LICENSE.txt
66
+ - README.md
67
+ - Rakefile
68
+ - lib/salary_calc.rb
69
+ - lib/salary_calc/conversions/from_hourly.rb
70
+ - lib/salary_calc/conversions/to_hourly.rb
71
+ - lib/salary_calc/version.rb
72
+ - salary_calc.gemspec
73
+ - spec/salary_calc_spec.rb
74
+ - spec/spec_helper.rb
75
+ homepage: ''
76
+ licenses:
77
+ - MIT
78
+ metadata: {}
79
+ post_install_message:
80
+ rdoc_options: []
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ! '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ! '>='
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ requirements: []
94
+ rubyforge_project:
95
+ rubygems_version: 2.1.3
96
+ signing_key:
97
+ specification_version: 4
98
+ summary: A very simple salary calculator
99
+ test_files:
100
+ - spec/salary_calc_spec.rb
101
+ - spec/spec_helper.rb
102
+ has_rdoc: