Class: BlendSpreadsheetLoanGenerator::Generate
- Inherits:
-
Dry::CLI::Command
- Object
- Dry::CLI::Command
- BlendSpreadsheetLoanGenerator::Generate
- Includes:
- CsvConcern, SpreadsheetConcern
- Defined in:
- lib/blend_spreadsheet_loan_generator/generate.rb
Instance Attribute Summary collapse
-
#loan ⇒ Object
Returns the value of attribute loan.
Instance Method Summary collapse
Instance Attribute Details
#loan ⇒ Object
Returns the value of attribute loan.
6 7 8 |
# File 'lib/blend_spreadsheet_loan_generator/generate.rb', line 6 def loan @loan end |
Instance Method Details
#call(amount:, duration:, rate:, **options) ⇒ Object
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 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/blend_spreadsheet_loan_generator/generate.rb', line 25 def call(amount:, duration:, rate:, **) begin session = GoogleDrive::Session.from_config( File.join(ENV['SPREADSHEET_LOAN_GENERATOR_DIR'], 'config.json') ) rescue StandardError => e if ENV['SPREADSHEET_LOAN_GENERATOR_DIR'].blank? puts 'please set SPREADSHEET_LOAN_GENERATOR_DIR' else puts 'Cannot connect to google drive. Did you run slg init CLIENT_ID CLIENT_SECRET ?' end return end @loan = Loan.new( amount: amount, duration: duration, period_duration: .fetch(:period_duration), rate: rate, due_on: .fetch(:due_on), deferred_and_capitalized: .fetch(:deferred_and_capitalized), deferred: .fetch(:deferred), type: .fetch(:type), interests_type: .fetch(:interests_type), starting_capitalized_interests: .fetch(:starting_capitalized_interests), starting_capitalized_fees: .fetch(:starting_capitalized_fees), fees_rate: .fetch(:fees_rate) ) spreadsheet = session.create_spreadsheet(loan.name) worksheet = spreadsheet.add_worksheet(loan.type, loan.duration + 2, columns.count + 1, index: 0) @formula = Formula.new(loan: loan) apply_formulas(worksheet: worksheet) apply_formats(worksheet: worksheet) worksheet.save worksheet.reload generate_csv(worksheet: worksheet, target_path: .fetch(:target_path)) puts worksheet.human_url end |