Class: Rfc::Generator
- Inherits:
-
Object
- Object
- Rfc::Generator
- Defined in:
- lib/rfc/generator.rb
Defined Under Namespace
Classes: InvalidDateError
Instance Method Summary collapse
- #for_legal_entity(legal_name:, day: nil, month: nil, year: nil, constitution_date: nil) ⇒ Object
- #for_natural_person(name:, first_last_name:, second_last_name:, day: nil, month: nil, year: nil, date_of_birth: nil) ⇒ Object
-
#initialize(natural_ten_digits_calculator: NaturalTenDigitsCodeCalculator, legal_entity_ten_digits_calculator: LegalEntityTenDigitsCodeCalculator, homoclave_calculator: HomoclaveCalculator, verification_digit_calculator: VerificationDigitCalculator) ⇒ Generator
constructor
A new instance of Generator.
Constructor Details
#initialize(natural_ten_digits_calculator: NaturalTenDigitsCodeCalculator, legal_entity_ten_digits_calculator: LegalEntityTenDigitsCodeCalculator, homoclave_calculator: HomoclaveCalculator, verification_digit_calculator: VerificationDigitCalculator) ⇒ Generator
Returns a new instance of Generator.
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/rfc/generator.rb', line 9 def initialize( natural_ten_digits_calculator: NaturalTenDigitsCodeCalculator, legal_entity_ten_digits_calculator: LegalEntityTenDigitsCodeCalculator, homoclave_calculator: HomoclaveCalculator, verification_digit_calculator: VerificationDigitCalculator ) @natural_ten_digits_calculator = natural_ten_digits_calculator @legal_entity_ten_digits_calculator = legal_entity_ten_digits_calculator @homoclave_calculator = homoclave_calculator @verification_digit_calculator = verification_digit_calculator end |
Instance Method Details
#for_legal_entity(legal_name:, day: nil, month: nil, year: nil, constitution_date: nil) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/rfc/generator.rb', line 52 def for_legal_entity( legal_name:, day: nil, month: nil, year: nil, constitution_date: nil ) normalized_day, normalized_month, normalized_year = normalize_date(day, month, year, constitution_date) ten_digits_code = @legal_entity_ten_digits_calculator.new( legal_name: legal_name, day: normalized_day, month: normalized_month, year: normalized_year ).calculate homoclave = @homoclave_calculator.new(legal_name: legal_name).calculate build_rfc(ten_digits_code, homoclave) rescue ArgumentError => e raise InvalidDateError, "Invalid date parameters: #{e.}" end |
#for_natural_person(name:, first_last_name:, second_last_name:, day: nil, month: nil, year: nil, date_of_birth: nil) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/rfc/generator.rb', line 21 def for_natural_person( name:, first_last_name:, second_last_name:, day: nil, month: nil, year: nil, date_of_birth: nil ) normalized_day, normalized_month, normalized_year = normalize_date(day, month, year, date_of_birth) ten_digits_code = @natural_ten_digits_calculator.new( name: name, first_last_name: first_last_name, second_last_name: second_last_name, day: normalized_day, month: normalized_month, year: normalized_year ).calculate homoclave = @homoclave_calculator.new( name: name, first_last_name: first_last_name, second_last_name: second_last_name ).calculate build_rfc(ten_digits_code, homoclave) rescue ArgumentError => e raise InvalidDateError, "Invalid date parameters: #{e.}" end |