csv_plus_plus 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a4462a2a82490271a95479970e10246ed7d8b1e8a62d21928a5f2b710b2bd511
4
- data.tar.gz: 31ce301945c5cc4d3154395dfa62271637baba4af78d2efed9b13d779036e015
3
+ metadata.gz: c29d586e678385367fe7a4a67fa66f4f0d111ceb1ace46125daaecbdd0bf7b03
4
+ data.tar.gz: aa13e49605c6448aa61cbf6d64ac39f3cfd9d8f84cb20370d8129ab5f1dd6f4b
5
5
  SHA512:
6
- metadata.gz: a968bc15a47a6ac129b0a4a13df3dfb1997991548f13af9ac28598091b5562be8d7d1943a03f86a1a501533ff2eb974d1e2cc788f43fca27f09be455edcdba9f
7
- data.tar.gz: f091403bede1fb2e751fad9b6937a836f0676e5ab284690fa2c8983fa746d90e9780c701d3a7ca1161fa9aca04b84263a1b7e7789dda866d6fe1caf975593287
6
+ metadata.gz: 6736fa3154f3ad44a4b3737a7d6e3b6571f6ba34226a8be4191a6cce3a53b1bcd09057b25bbc96da0ad01cc8c397e7b78df379b48fd510f881a810e8754aec65
7
+ data.tar.gz: 8160d63e5bda5417619d6a6e4e2a73b5cee744fc26b356d2c36efe3c56b93e2cfda8ed5cb128758079463542d0306d634c4804e02b7e4c56c14d9b98b0f3c1db
data/README.md CHANGED
@@ -1,3 +1,7 @@
1
+ # Deprecated!!!
2
+
3
+ This version of csv++ is deprecated. For the current version please go to [github.com/patrickomatic/csv-plus-plus](https://github.com/patrickomatic/csv-plus-plus)
4
+
1
5
  ![main](https://github.com/patrickomatic/csv-plus-plus/actions/workflows/rspec.yml/badge.svg)
2
6
  [![Ruby Style Guide](https://img.shields.io/badge/code_style-community-brightgreen.svg)](https://rubystyle.guide)
3
7
  [![Gem Version](https://badge.fury.io/rb/csv_plus_plus.svg)](https://badge.fury.io/rb/csv_plus_plus)
@@ -59,6 +63,7 @@ Usage: csv++ [options]
59
63
  -k, --key-values KEY_VALUES A comma-separated list of key=values which will be made available to the template
60
64
  -n, --sheet-name SHEET_NAME The name of the sheet to apply the template to
61
65
  -o, --output OUTPUT_FILE The file to write to (must be .csv, .ods, .xls)
66
+ -s, --safe Do not overwrite values in the spreadsheet being written to. The default is to overwrite
62
67
  -v, --verbose Enable verbose output
63
68
  -x, --offset-columns OFFSET Apply the template offset by OFFSET cells
64
69
  -y, --offset-rows OFFSET Apply the template offset by OFFSET rows
data/docs/CHANGELOG.md CHANGED
@@ -1,4 +1,6 @@
1
- ## main/upcoming
1
+ ## main
2
+
3
+ - Add a `-s`/`--safe` flag which changes the merge strategy to not overwrite existing values. If the spreadsheet being written to has values where the csvpp template wants to write, they will be overwritten otherwise.
2
4
 
3
5
  ## v0.2.0
4
6
 
@@ -46,6 +46,7 @@ module CSVPlusPlus
46
46
  'offset-columns': ->(options, v) { options.offset[0] = v },
47
47
  'offset-rows': ->(options, v) { options.offset[1] = v },
48
48
  output: ->(options, v) { options.output_filename = ::Pathname.new(v) },
49
+ safe: ->(options, _v) { options.overwrite_values = false },
49
50
  verbose: ->(options, _v) { options.verbose = true }
50
51
  },
51
52
  ::T::Hash[::Symbol, ::T.proc.params(options: ::CSVPlusPlus::Options::Options, v: ::String).void]
@@ -81,6 +82,11 @@ module CSVPlusPlus
81
82
  '--output OUTPUT_FILE',
82
83
  'The file to write to (must be .csv, .ods, .xls)'
83
84
  ),
85
+ ::CSVPlusPlus::CLIFlag.new(
86
+ '-s',
87
+ '--safe',
88
+ 'Do not overwrite values in the spreadsheet being written to. The default is to overwrite'
89
+ ),
84
90
  ::CSVPlusPlus::CLIFlag.new('-v', '--verbose', 'Enable verbose output'),
85
91
  ::CSVPlusPlus::CLIFlag.new('-x OFFSET', '--offset-columns OFFSET', 'Apply the template offset by OFFSET cells'),
86
92
  ::CSVPlusPlus::CLIFlag.new('-y OFFSET', '--offset-rows OFFSET', 'Apply the template offset by OFFSET rows')
@@ -9,6 +9,7 @@ module CSVPlusPlus
9
9
  # @attr create_if_not_exists [Boolean] Create the spreadsheet if it does not exist?
10
10
  # @attr key_values [Hash] Additional variables that can be supplied to the template
11
11
  # @attr offset [Array<Integer>] An [x, y] offset (array with two integers)
12
+ # @attr overwrite_values [Boolean] Whether or not to overwrite existing values in the output spreadsheet.
12
13
  # @attr sheet_name [String] The name of the spreadsheet to write to
13
14
  # @attr verbose [Boolean] Include extra verbose output?
14
15
  class Options
@@ -29,6 +30,9 @@ module CSVPlusPlus
29
30
  sig { returns(::T::Array[::Integer]) }
30
31
  attr_accessor :offset
31
32
 
33
+ sig { returns(::T::Boolean) }
34
+ attr_accessor :overwrite_values
35
+
32
36
  sig { returns(::String) }
33
37
  attr_accessor :sheet_name
34
38
 
@@ -38,12 +42,13 @@ module CSVPlusPlus
38
42
  sig { params(sheet_name: ::String).void }
39
43
  # Initialize a defaul +Options+ object
40
44
  def initialize(sheet_name)
41
- @sheet_name = sheet_name
42
- @offset = ::T.let([0, 0], ::T::Array[::Integer])
45
+ @backup = ::T.let(false, ::T::Boolean)
43
46
  @create_if_not_exists = ::T.let(false, ::T::Boolean)
44
47
  @key_values = ::T.let({}, ::T::Hash[::Symbol, ::CSVPlusPlus::Entities::Entity])
48
+ @offset = ::T.let([0, 0], ::T::Array[::Integer])
49
+ @overwrite_values = ::T.let(true, ::T::Boolean)
50
+ @sheet_name = sheet_name
45
51
  @verbose = ::T.let(false, ::T::Boolean)
46
- @backup = ::T.let(false, ::T::Boolean)
47
52
  end
48
53
 
49
54
  sig { abstract.returns(::CSVPlusPlus::Options::OutputFormat) }
@@ -2,6 +2,6 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module CSVPlusPlus
5
- VERSION = '0.2.0'
5
+ VERSION = '0.2.1'
6
6
  public_constant :VERSION
7
7
  end
@@ -16,16 +16,41 @@ module CSVPlusPlus
16
16
  options: ::CSVPlusPlus::Options::Options
17
17
  ).returns(::T.nilable(::T.type_parameter(:V)))
18
18
  end
19
- # Our strategy for resolving differences between new changes and existing
19
+ # Consistently enforce our strategy for resolving differences between new changes and existing. By default we
20
+ # overwrite values that are currently in the spreadsheet but you can override that with the --safe flag
20
21
  def merge_cell_value(existing_value:, new_value:, options:)
21
- # TODO: make an option that specifies if we override (take new data over old)
22
- merged_value = new_value || existing_value
22
+ merged_value = merge_with_strategy(existing_value:, new_value:, options:)
23
23
 
24
- return merged_value if !options.verbose || merged_value == existing_value
24
+ return merged_value unless options.verbose
25
+
26
+ if options.overwrite_values && merged_value != existing_value
27
+ warn("Overwriting existing value: \"#{existing_value}\" with \"#{new_value}\"")
28
+ # rubocop:disable Style/MissingElse
29
+ elsif !options.overwrite_values && new_value != merged_value
30
+ # rubocop:enable Style/MissingElse
31
+ warn("Keeping old value: \"#{existing_value}\" rather than new value: \"#{new_value}\"")
32
+ end
25
33
 
26
- warn("Overwriting existing value: \"#{existing_value}\" with \"#{new_value}\"")
27
34
  merged_value
28
35
  end
36
+
37
+ private
38
+
39
+ sig do
40
+ type_parameters(:V)
41
+ .params(
42
+ existing_value: ::T.nilable(::T.all(::T.type_parameter(:V), ::BasicObject)),
43
+ new_value: ::T.nilable(::T.all(::T.type_parameter(:V), ::BasicObject)),
44
+ options: ::CSVPlusPlus::Options::Options
45
+ ).returns(::T.nilable(::T.type_parameter(:V)))
46
+ end
47
+ def merge_with_strategy(existing_value:, new_value:, options:)
48
+ if options.overwrite_values
49
+ new_value || existing_value
50
+ else
51
+ existing_value || new_value
52
+ end
53
+ end
29
54
  end
30
55
  end
31
56
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: csv_plus_plus
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Patrick Carroll
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-05-15 00:00:00.000000000 Z
11
+ date: 2023-09-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: google-apis-drive_v3
@@ -212,16 +212,16 @@ files:
212
212
  - lib/csv_plus_plus/writer/open_document.rb
213
213
  - lib/csv_plus_plus/writer/rubyxl_builder.rb
214
214
  - lib/csv_plus_plus/writer/writer.rb
215
- homepage: https://github.com/patrickomatic/csv-plus-plus
215
+ homepage: https://github.com/patrickomatic/csv-plus-plus-ruby
216
216
  licenses:
217
217
  - MIT
218
218
  metadata:
219
- bug_tracker_uri: https://github.com/patrickomatic/csv-plus-plus/issues
219
+ bug_tracker_uri: https://github.com/patrickomatic/csv-plus-plus-ruby/issues
220
220
  documentation_uri: https://www.rubydoc.info/gems/csv_plus_plus/
221
- github_repo: git://github.com/patrickomatic/csv-plus-plus
222
- homepage_uri: https://github.com/patrickomatic/csv-plus-plus
223
- source_code_uri: https://github.com/patrickomatic/csv-plus-plus
224
- changelog_uri: https://github.com/patrickomatic/csv-plus-plus/blob/main/docs/CHANGELOG.md
221
+ github_repo: git://github.com/patrickomatic/csv-plus-plus-ruby
222
+ homepage_uri: https://github.com/patrickomatic/csv-plus-plus-ruby
223
+ source_code_uri: https://github.com/patrickomatic/csv-plus-plus-ruby
224
+ changelog_uri: https://github.com/patrickomatic/csv-plus-plus-ruby/blob/main/docs/CHANGELOG.md
225
225
  rubygems_mfa_required: 'true'
226
226
  post_install_message:
227
227
  rdoc_options: []