Module: CSVPlusPlus
- Extended by:
- T::Sig
- Defined in:
- lib/csv_plus_plus.rb,
lib/csv_plus_plus/cli.rb,
lib/csv_plus_plus/row.rb,
lib/csv_plus_plus/cell.rb,
lib/csv_plus_plus/color.rb,
lib/csv_plus_plus/error.rb,
lib/csv_plus_plus/lexer.rb,
lib/csv_plus_plus/reader.rb,
lib/csv_plus_plus/writer.rb,
lib/csv_plus_plus/options.rb,
lib/csv_plus_plus/runtime.rb,
lib/csv_plus_plus/version.rb,
lib/csv_plus_plus/cli_flag.rb,
lib/csv_plus_plus/compiler.rb,
lib/csv_plus_plus/entities.rb,
lib/csv_plus_plus/modifier.rb,
lib/csv_plus_plus/template.rb,
lib/csv_plus_plus/reader/csv.rb,
lib/csv_plus_plus/writer/csv.rb,
lib/csv_plus_plus/error/error.rb,
lib/csv_plus_plus/source_code.rb,
lib/csv_plus_plus/a1_reference.rb,
lib/csv_plus_plus/writer/excel.rb,
lib/csv_plus_plus/entities/date.rb,
lib/csv_plus_plus/reader/reader.rb,
lib/csv_plus_plus/reader/rubyxl.rb,
lib/csv_plus_plus/runtime/graph.rb,
lib/csv_plus_plus/runtime/scope.rb,
lib/csv_plus_plus/writer/merger.rb,
lib/csv_plus_plus/writer/writer.rb,
lib/csv_plus_plus/entities/entity.rb,
lib/csv_plus_plus/entities/number.rb,
lib/csv_plus_plus/entities/string.rb,
lib/csv_plus_plus/error/cli_error.rb,
lib/csv_plus_plus/error_formatter.rb,
lib/csv_plus_plus/lexer/tokenizer.rb,
lib/csv_plus_plus/modifier/expand.rb,
lib/csv_plus_plus/options/options.rb,
lib/csv_plus_plus/runtime/runtime.rb,
lib/csv_plus_plus/entities/boolean.rb,
lib/csv_plus_plus/lexer/racc_lexer.rb,
lib/csv_plus_plus/runtime/position.rb,
lib/csv_plus_plus/entities/builtins.rb,
lib/csv_plus_plus/entities/function.rb,
lib/csv_plus_plus/google_api_client.rb,
lib/csv_plus_plus/modifier/modifier.rb,
lib/csv_plus_plus/entities/reference.rb,
lib/csv_plus_plus/error/writer_error.rb,
lib/csv_plus_plus/runtime/references.rb,
lib/csv_plus_plus/parser/modifier.tab.rb,
lib/csv_plus_plus/benchmarked_compiler.rb,
lib/csv_plus_plus/entities/ast_builder.rb,
lib/csv_plus_plus/error/compiler_error.rb,
lib/csv_plus_plus/options/file_options.rb,
lib/csv_plus_plus/reader/google_sheets.rb,
lib/csv_plus_plus/writer/google_sheets.rb,
lib/csv_plus_plus/writer/open_document.rb,
lib/csv_plus_plus/parser/cell_value.tab.rb,
lib/csv_plus_plus/writer/rubyxl_builder.rb,
lib/csv_plus_plus/entities/function_call.rb,
lib/csv_plus_plus/entities/runtime_value.rb,
lib/csv_plus_plus/error/positional_error.rb,
lib/csv_plus_plus/entities/has_identifier.rb,
lib/csv_plus_plus/parser/code_section.tab.rb,
lib/csv_plus_plus/modifier/data_validation.rb,
lib/csv_plus_plus/modifier/rubyxl_modifier.rb,
lib/csv_plus_plus/writer/file_backer_upper.rb,
lib/csv_plus_plus/error/formula_syntax_error.rb,
lib/csv_plus_plus/error/modifier_syntax_error.rb,
lib/csv_plus_plus/modifier/modifier_validator.rb,
lib/csv_plus_plus/writer/google_sheets_builder.rb,
lib/csv_plus_plus/options/google_sheets_options.rb,
lib/csv_plus_plus/entities/entity_with_arguments.rb,
lib/csv_plus_plus/modifier/google_sheet_modifier.rb,
lib/csv_plus_plus/error/modifier_validation_error.rb,
lib/csv_plus_plus/modifier/conditional_formatting.rb
Overview
typed: true frozen_string_literal: true
Defined Under Namespace
Modules: Entities, Error, GoogleApiClient, Lexer, Modifier, Options, Parser, Reader, Runtime, Writer Classes: A1Reference, BenchmarkedCompiler, CLI, CLIFlag, Cell, Color, Compiler, ErrorFormatter, Row, SourceCode, Template
Constant Summary collapse
- VERSION =
'0.2.1'
- FLAG_HANDLERS =
::T.let( { backup: ->(, _v) { .backup = true }, create: ->(, _v) { .create_if_not_exists = true }, 'key-values': lambda { |, v| .key_values = begin [v.split('=')].to_h rescue ::StandardError {} end }, 'offset-columns': ->(, v) { .offset[0] = v }, 'offset-rows': ->(, v) { .offset[1] = v }, output: ->(, v) { .output_filename = ::Pathname.new(v) }, safe: ->(, _v) { .overwrite_values = false }, verbose: ->(, _v) { .verbose = true } }, ::T::Hash[::Symbol, ::T.proc.params(options: ::CSVPlusPlus::Options::Options, v: ::String).void] )
- SUPPORTED_CSVPP_FLAGS =
::T.let( [ ::CSVPlusPlus::CLIFlag.new('-b', '--backup', 'Create a backup of the spreadsheet before applying changes.'), ::CSVPlusPlus::CLIFlag.new( '-c', '--create', "Create the sheet if it doesn't exist. It will use --sheet-name if specified" ), ::CSVPlusPlus::CLIFlag.new( '-g SHEET_ID', '--google-sheet-id SHEET_ID', 'The id of the sheet - you can extract this from the URL: ' \ 'https://docs.google.com/spreadsheets/d/< ... SHEET_ID ... >/edit#gid=0' ), ::CSVPlusPlus::CLIFlag.new( '-k', '--key-values KEY_VALUES', 'A comma-separated list of key=values which will be made available to the template' ), ::CSVPlusPlus::CLIFlag.new( '-n SHEET_NAME', '--sheet-name SHEET_NAME', 'The name of the sheet to apply the template to' ), ::CSVPlusPlus::CLIFlag.new( '-o OUTPUT_FILE', '--output OUTPUT_FILE', 'The file to write to (must be .csv, .ods, .xls)' ), ::CSVPlusPlus::CLIFlag.new( '-s', '--safe', 'Do not overwrite values in the spreadsheet being written to. The default is to overwrite' ), ::CSVPlusPlus::CLIFlag.new('-v', '--verbose', 'Enable verbose output'), ::CSVPlusPlus::CLIFlag.new('-x OFFSET', '--offset-columns OFFSET', 'Apply the template offset by OFFSET cells'), ::CSVPlusPlus::CLIFlag.new('-y OFFSET', '--offset-rows OFFSET', 'Apply the template offset by OFFSET rows') ].freeze, ::T::Array[::CSVPlusPlus::CLIFlag] )
Class Method Summary collapse
-
.cli_compile(source_code, options) ⇒ Object
Parse the input into a
Template
and write it to the desired format. -
.write_template(compiler:, options:, template:) ⇒ Object
Write the results (and possibly make a backup) of a compiled
template
.
Class Method Details
.cli_compile(source_code, options) ⇒ Object
Parse the input into a Template
and write it to the desired format
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/csv_plus_plus.rb', line 61 def self.cli_compile(source_code, ) runtime = ::CSVPlusPlus::Runtime.new(source_code:) warn(.verbose_summary) if .verbose ::CSVPlusPlus::Compiler.with_compiler(options:, runtime:) do |compiler| template = compiler.compile_template warn(template.verbose_summary) if .verbose write_template(template:, compiler:, options:) end rescue ::StandardError => e ::CSVPlusPlus::ErrorFormatter.new(runtime: ::T.must(runtime), options:).handle_error(e) # the caller will exit(1) raise(e) end |
.write_template(compiler:, options:, template:) ⇒ Object
Write the results (and possibly make a backup) of a compiled template
90 91 92 93 94 95 96 |
# File 'lib/csv_plus_plus.rb', line 90 def self.write_template(compiler:, options:, template:) compiler.outputting! do |position| output = ::CSVPlusPlus::Writer.writer(, position) output.write_backup if .backup output.write(template) end end |