brir 0.2.0 → 0.2.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.
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - "1.9.2"
4
+ - "1.9.3"
data/README.md CHANGED
@@ -1,6 +1,8 @@
1
1
  # Brir
2
2
 
3
- Brir is a interface to calculate the Brazilian Income Tax (Imposto de Renda Brasileiro - IRPF & IRPJ).
3
+ [![Build Status](https://secure.travis-ci.org/squiter85/brir.png)](http://travis-ci.org/squiter85/brir)
4
+
5
+ Brir is a interface to calculate the Brazilian Income Tax (Imposto de Renda Brasileiro - IRPF & IRPJ).
4
6
  This gem was created to solve a unique issue that is calculate how many money the brazilians will pay to your country over your anual income.
5
7
 
6
8
  ## Installation
@@ -20,27 +22,27 @@ Or install it yourself as:
20
22
  ## Usage
21
23
 
22
24
  require 'brir'
23
-
25
+
24
26
  # chose the exercise year or leave blank to use actual year
25
27
  brir = Brir.new 2012
26
-
28
+
27
29
  # call tax method passing your taxable income
28
30
  income_tax_value = brir.tax 42000
29
-
31
+
30
32
  puts income_tax_value
31
- #=> 3109.53
33
+ #=> 3109.53
32
34
 
33
35
  ## Progressive Table
34
36
 
35
- This gem already have a progressive table with the following exercise years (Financial Year):
37
+ This gem already have a progressive table with the following exercise years (Financial Year):
36
38
 
37
- * 2012
38
- * 2013
39
- * 2014
39
+ * 2012
40
+ * 2013
41
+ * 2014
40
42
  * 2015
41
43
 
42
- If you want to use your own Progressive Table, you must to create a YAML file into your config path. (Only for Rails Applications).
43
- The file must be like these:
44
+ If you want to use your own Progressive Table, you must to create a YAML file into your config path. (Only for Rails Applications).
45
+ The file must be like these:
44
46
 
45
47
  2012:
46
48
  ranges:
@@ -1,70 +1,58 @@
1
1
  module Brir
2
2
  class BrirApi
3
3
  attr_accessor :exercise_year, :calendar_year, :ranges
4
-
4
+
5
5
  def initialize(exercise_year = nil)
6
6
  @exercise_year = (exercise_year.nil?) ? Time.new.year : exercise_year
7
7
  @calendar_year = @exercise_year.to_i - 1
8
8
  @ranges = table(@exercise_year)
9
+ raise "Fail to initialize the progressive table" if @ranges.nil?
9
10
  end
10
-
11
+
11
12
  def tax(income)
12
-
13
+
13
14
  # prevent negative incomes
14
15
  income = income.to_f.round 2
15
16
  return 0.00 unless income > 0
16
-
17
+
17
18
  case income
18
19
  when @ranges["second"]["from"]..@ranges["second"]["to"]
19
-
20
- # secound range
21
- total = (((income.to_f - @ranges["second"]["from"])*@ranges["second"]["aliquot"])/100)
22
-
20
+ total = calc_second_range(income)
23
21
  when @ranges["third"]["from"]..@ranges["third"]["to"]
24
-
25
- # third range
26
- total = (((@ranges["second"]["to"] - @ranges["second"]["from"])*@ranges["second"]["aliquot"])/100)
27
- total = (total.round 2) + (((income.to_f - @ranges["second"]["to"])*@ranges["third"]["aliquot"])/100)
28
-
22
+ total = calc_third_range(income)
29
23
  when @ranges["fourth"]["from"]..@ranges["fourth"]["to"]
30
-
31
- # fourth range
32
- total = (((@ranges["second"]["to"] - @ranges["second"]["from"])*@ranges["second"]["aliquot"])/100)
33
- total = (total.round 2) + (((@ranges["third"]["to"] - @ranges["second"]["to"])*@ranges["third"]["aliquot"])/100)
34
- total = (total.round 2) + (((income.to_f - @ranges["third"]["to"])*@ranges["fourth"]["aliquot"])/100)
35
-
24
+ total = calc_fourth_range(income)
36
25
  when @ranges["fifth"]["from"]..(1.0/0.0)
37
-
38
- #fifth range
39
- total = (((@ranges["second"]["to"] - @ranges["second"]["from"])*@ranges["second"]["aliquot"])/100)
40
- total = (total.round 2) + (((@ranges["third"]["to"] - @ranges["second"]["to"])*@ranges["third"]["aliquot"])/100)
41
- total = (total.round 2) + (((@ranges["fourth"]["to"] - @ranges["third"]["to"])*@ranges["fourth"]["aliquot"])/100)
42
- total = (total.round 2) + (((income.to_f - @ranges["fourth"]["to"])*@ranges["fifth"]["aliquot"])/100)
43
-
26
+ total = calc_fifth_range(income)
44
27
  else
45
28
  total = 0.00
46
29
  end
47
30
  total.to_f.round 2
48
31
  end
49
-
32
+
50
33
  private
51
34
  def set_progressive_table()
52
35
  require 'yaml'
53
-
36
+
54
37
  begin
55
38
  # Trying to get brir.yml into config path, for Rails Applications
56
39
  file = File.join(Rails.root, "config", "brir.yml")
40
+
41
+ # I realy don't know if this is the best solution to this
42
+ unless File.exists? file
43
+ file = File.join(File.dirname(__FILE__),"table_source", "progressiveTable.yml")
44
+ end
57
45
  rescue
58
- file = File.join(File.dirname(__FILE__),"table_source/progressiveTable.yml")
46
+ file = File.join(File.dirname(__FILE__),"table_source", "progressiveTable.yml")
59
47
  end
60
-
48
+
61
49
  begin
62
50
  yaml = YAML.load_file(file)
63
51
  rescue Errno::ENOENT
64
- puts "Fails"
52
+ raise "Brir fails to load progressive table"
65
53
  end
66
54
  end
67
-
55
+
68
56
  def table(exercise_year)
69
57
  yaml = set_progressive_table()
70
58
  begin
@@ -73,6 +61,31 @@ module Brir
73
61
  nil
74
62
  end
75
63
  end
76
-
64
+
65
+ def calc_second_range(income)
66
+ (((income.to_f - @ranges["second"]["from"])*@ranges["second"]["aliquot"])/100)
67
+ end
68
+
69
+ def calc_third_range(income)
70
+ total = (((@ranges["second"]["to"] - @ranges["second"]["from"])*@ranges["second"]["aliquot"])/100)
71
+ total = (total.round 2) + (((income.to_f - @ranges["second"]["to"])*@ranges["third"]["aliquot"])/100)
72
+ total
73
+ end
74
+
75
+ def calc_fourth_range(income)
76
+ total = (((@ranges["second"]["to"] - @ranges["second"]["from"])*@ranges["second"]["aliquot"])/100)
77
+ total = (total.round 2) + (((@ranges["third"]["to"] - @ranges["second"]["to"])*@ranges["third"]["aliquot"])/100)
78
+ total = (total.round 2) + (((income.to_f - @ranges["third"]["to"])*@ranges["fourth"]["aliquot"])/100)
79
+ total
80
+ end
81
+
82
+ def calc_fifth_range(income)
83
+ total = (((@ranges["second"]["to"] - @ranges["second"]["from"])*@ranges["second"]["aliquot"])/100)
84
+ total = (total.round 2) + (((@ranges["third"]["to"] - @ranges["second"]["to"])*@ranges["third"]["aliquot"])/100)
85
+ total = (total.round 2) + (((@ranges["fourth"]["to"] - @ranges["third"]["to"])*@ranges["fourth"]["aliquot"])/100)
86
+ total = (total.round 2) + (((income.to_f - @ranges["fourth"]["to"])*@ranges["fifth"]["aliquot"])/100)
87
+ total
88
+ end
89
+
77
90
  end
78
91
  end
@@ -1,3 +1,3 @@
1
1
  module Brir
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: brir
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-09-28 00:00:00.000000000 Z
12
+ date: 2012-10-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -52,6 +52,7 @@ extensions: []
52
52
  extra_rdoc_files: []
53
53
  files:
54
54
  - .gitignore
55
+ - .travis.yml
55
56
  - Gemfile
56
57
  - LICENSE
57
58
  - README.md