Class: Steuer::Steuernummer
- Inherits:
-
Object
- Object
- Steuer::Steuernummer
- Defined in:
- lib/steuer/steuernummer.rb
Instance Attribute Summary collapse
-
#original_input ⇒ Object
readonly
Returns the value of attribute original_input.
-
#state_code ⇒ Object
readonly
Returns the value of attribute state_code.
Instance Method Summary collapse
- #format_type ⇒ Object
-
#initialize(tax_number, state: nil) ⇒ Steuernummer
constructor
A new instance of Steuernummer.
- #state_name ⇒ Object
- #to_federal_12 ⇒ Object
- #to_federal_13 ⇒ Object (also: #to_elster)
- #to_standard ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(tax_number, state: nil) ⇒ Steuernummer
9 10 11 12 13 14 15 |
# File 'lib/steuer/steuernummer.rb', line 9 def initialize(tax_number, state: nil) @original_input = tax_number.to_s.strip @explicit_state_code = normalize_state_code(state) @state_code = @explicit_state_code || auto_detect_state validate_tax_number! end |
Instance Attribute Details
#original_input ⇒ Object (readonly)
Returns the value of attribute original_input.
7 8 9 |
# File 'lib/steuer/steuernummer.rb', line 7 def original_input @original_input end |
#state_code ⇒ Object (readonly)
Returns the value of attribute state_code.
7 8 9 |
# File 'lib/steuer/steuernummer.rb', line 7 def state_code @state_code end |
Instance Method Details
#format_type ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/steuer/steuernummer.rb', line 79 def format_type @format_type ||= if normalized_input.include?('/') :standard elsif normalized_input.length == 12 && normalized_input.match?(/^\d{12}$/) :federal_12 elsif normalized_input.length == 13 && normalized_input.match?(/^\d{13}$/) :federal_13 elsif unseparated_standard? :standard end @format_type end |
#state_name ⇒ Object
73 74 75 76 77 |
# File 'lib/steuer/steuernummer.rb', line 73 def state_name return unless @state_code StateMapping::STATES[@state_code][:name] end |
#to_federal_12 ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/steuer/steuernummer.rb', line 34 def to_federal_12 return unless valid? case format_type when :standard convert_standard_to_federal_12 when :federal_12 normalized_input when :federal_13 convert_federal_13_to_federal_12 end end |
#to_federal_13 ⇒ Object Also known as: to_elster
47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/steuer/steuernummer.rb', line 47 def to_federal_13 return unless valid? case format_type when :standard convert_standard_to_federal_13 when :federal_12 convert_federal_12_to_federal_13 when :federal_13 normalized_input end end |
#to_standard ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/steuer/steuernummer.rb', line 60 def to_standard return unless valid? case format_type when :standard canonical_standard_input || @original_input when :federal_12 convert_federal_12_to_standard when :federal_13 convert_federal_13_to_standard end end |
#valid? ⇒ Boolean
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/steuer/steuernummer.rb', line 17 def valid? return false if @original_input.empty? return false unless format_type return false unless @state_code case format_type when :standard validate_standard_format when :federal_12 validate_federal_12_format when :federal_13 validate_federal_13_format else false end end |