csvbuilder-dynamic-columns-importer 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fae90eb58f14072abf9068c09b125a5b6d44948a246cb83cd90c6456848d876f
4
- data.tar.gz: 93999aae3ddd011a8784df49be8bf05b184bf5c1bd3d24c54d6144b42e874d81
3
+ metadata.gz: 5284cad3a4cc3874ea844be65d971b3e0b7a0245245de9d01820660e73e72ee1
4
+ data.tar.gz: 1fab65090d75e6b553d29df8be9ad6dee579b0183e0bcc14eff20349fd4c2fb6
5
5
  SHA512:
6
- metadata.gz: 11d103d4abc5a98e72436bbf498aed37c31229d9e8923ea3af9636e3fd4f3e4adaa9e874c291ac3e5065ed7ccc81fb0cf43f50c573458fd3b5b63e899cd92441
7
- data.tar.gz: fcd52c72ed997f91515d785b79b5a14d65f9b23e7bca908e4c63a677ac51a95883954511de1229d53c0c01beb0f606f70a718efa6593689bc4265ead8aaeae58
6
+ metadata.gz: 843659c08e54ee2fc168d62725af79681a799c6c8490da2844a7d560d42c9f94a37ed79d11bb0a8a2379b6476f5d6e5b04891b0a31910a5bd81ebe741337ddc8
7
+ data.tar.gz: cf128b9754fa9de72f140a2924e10408bf4dd9b42c1f1d150ebcb6d136d69a4a99fbf107930003dbe7d3d4441b9dbcd8bc8eac1d01aee072ba36de83a41a3ac1
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.1.1] - 2022-12-30
4
+
5
+ Do not apply double formatting to the cells. The method `unformatted_value` should get the raw values from `source_cells`, not the value already formatted by row_model.format_cell.
6
+
3
7
  ## [0.1.0] - 2022-12-21
4
8
 
5
9
  - Initial release
data/Gemfile.lock CHANGED
@@ -1,11 +1,11 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- csvbuilder-dynamic-columns-importer (0.1.0)
4
+ csvbuilder-dynamic-columns-importer (0.1.1)
5
5
  activesupport (>= 5.2, < 8)
6
- csvbuilder-core
7
- csvbuilder-dynamic-columns-core
8
- csvbuilder-importer
6
+ csvbuilder-core (~> 0.1)
7
+ csvbuilder-dynamic-columns-core (~> 0.1)
8
+ csvbuilder-importer (~> 0.1)
9
9
 
10
10
  GEM
11
11
  remote: https://rubygems.org/
@@ -65,7 +65,7 @@ GEM
65
65
  unicode-display_width (>= 1.4.0, < 3.0)
66
66
  rubocop-ast (1.24.0)
67
67
  parser (>= 3.1.1.0)
68
- rubocop-performance (1.15.1)
68
+ rubocop-performance (1.15.2)
69
69
  rubocop (>= 1.7.0, < 2.0)
70
70
  rubocop-ast (>= 0.4.0)
71
71
  rubocop-rake (0.6.0)
@@ -79,6 +79,7 @@ GEM
79
79
 
80
80
  PLATFORMS
81
81
  arm64-darwin-21
82
+ x86_64-linux
82
83
 
83
84
  DEPENDENCIES
84
85
  csvbuilder-dynamic-columns-importer!
data/README.md CHANGED
@@ -1,22 +1,85 @@
1
- # Csvbuilder::Dynamic::Columns
1
+ # Csvbuilder::Dynamic::Columns::Importer
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/csvbuilder/dynamic/columns`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ [Csvbuilder::Dynamic::Columns::Importer](https://github.com/joel/csvbuilder-dynamic-columns-importer) is part of the [csvbuilder-collection](https://github.com/joel/csvbuilder)
4
4
 
5
- TODO: Delete this and the text above, and describe your gem
5
+ The Dynamic Columns Importer contains the implementation for importing CSV data with a variable group, for instance, an object with categories.
6
6
 
7
7
  ## Installation
8
8
 
9
9
  Install the gem and add to the application's Gemfile by executing:
10
10
 
11
- $ bundle add csvbuilder-dynamic-columns
11
+ $ bundle add csvbuilder-dynamic-columns-importer
12
12
 
13
13
  If bundler is not being used to manage dependencies, install the gem by executing:
14
14
 
15
- $ gem install csvbuilder-dynamic-columns
15
+ $ gem install csvbuilder-dynamic-columns-importer
16
16
 
17
17
  ## Usage
18
18
 
19
- TODO: Write usage instructions here
19
+ Let's consider a Developer with languages skill.
20
+
21
+ ```ruby
22
+ class UserCsvImportModel
23
+ include Csvbuilder::Model
24
+ include Csvbuilder::Import
25
+
26
+ column :name, header: "Developer"
27
+
28
+ dynamic_column :skills
29
+ end
30
+ ```
31
+
32
+ The Row can iterate over the Dynamic Columns. Here are `skills`, and get access to the cell values.
33
+
34
+ For each entry of the Dynamic Columns, here `skills`, a method called by the singular version name of the declared Dynamic Columns will be called here `skill`.
35
+
36
+ This method provides the header value and the cell value; however, it returns only the cell value by default; if that is all that is needed, there is no need for overriding.
37
+
38
+ However, it is safe to override this method to put in place any logic needed.
39
+
40
+ For instance, returning the header and cell values to figure out what the importer has to do with them.
41
+
42
+ Check out the following example:
43
+
44
+ ```ruby
45
+ class UserCsvImportModel
46
+ include Csvbuilder::Model
47
+ include Csvbuilder::Import
48
+
49
+ column :name, header: "Developer"
50
+
51
+ dynamic_column :skills
52
+
53
+ def user
54
+ User.where(name: name).take
55
+ end
56
+
57
+ def skill(value, header_value)
58
+ { skill: header_value, has: value }
59
+ end
60
+ end
61
+ ```
62
+
63
+ ```ruby
64
+ [
65
+ ["Developer", "Ruby", "Python", "Javascript"],
66
+ ["Bob" , "1", "0", "1"],
67
+ ]
68
+ ```
69
+
70
+ ```ruby
71
+ options = {}
72
+
73
+ Csvbuilder::Import::File.new(file.path, UserCsvImportModel, options).each do |row_model|
74
+ row_model.skills.each do |skill_data|
75
+ skill = Skill.find_or_create_by(name: skill_data[:skill])
76
+ row_model.user.skills << skill if skill_data[:has] == "1"
77
+ end
78
+ end
79
+
80
+ User.where(name: "Bob").take.skills.pluck(:name)
81
+ # => ["Ruby", "Javascript"]
82
+ ```
20
83
 
21
84
  ## Development
22
85
 
@@ -26,7 +89,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
26
89
 
27
90
  ## Contributing
28
91
 
29
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/csvbuilder-dynamic-columns. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/csvbuilder-dynamic-columns/blob/main/CODE_OF_CONDUCT.md).
92
+ Bug reports and pull requests are welcome on GitHub at https://github.com/joel/csvbuilder-dynamic-columns. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/csvbuilder-dynamic-columns/blob/main/CODE_OF_CONDUCT.md).
30
93
 
31
94
  ## License
32
95
 
@@ -15,8 +15,8 @@ module Csvbuilder
15
15
  end
16
16
 
17
17
  def unformatted_value
18
- formatted_cells.zip(formatted_headers).map do |formatted_cell, source_headers|
19
- call_process_cell(formatted_cell, source_headers)
18
+ source_cells.zip(formatted_headers).map do |source_cell, formatted_header|
19
+ call_process_cell(source_cell, formatted_header)
20
20
  end
21
21
  end
22
22
 
@@ -4,7 +4,7 @@ module Csvbuilder
4
4
  module Dynamic
5
5
  module Columns
6
6
  module Importer
7
- VERSION = "0.1.0"
7
+ VERSION = "0.1.1"
8
8
  end
9
9
  end
10
10
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: csvbuilder-dynamic-columns-importer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joel Azemar
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-12-23 00:00:00.000000000 Z
11
+ date: 2022-12-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -34,44 +34,44 @@ dependencies:
34
34
  name: csvbuilder-core
35
35
  requirement: !ruby/object:Gem::Requirement
36
36
  requirements:
37
- - - ">="
37
+ - - "~>"
38
38
  - !ruby/object:Gem::Version
39
- version: '0'
39
+ version: '0.1'
40
40
  type: :runtime
41
41
  prerelease: false
42
42
  version_requirements: !ruby/object:Gem::Requirement
43
43
  requirements:
44
- - - ">="
44
+ - - "~>"
45
45
  - !ruby/object:Gem::Version
46
- version: '0'
46
+ version: '0.1'
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: csvbuilder-dynamic-columns-core
49
49
  requirement: !ruby/object:Gem::Requirement
50
50
  requirements:
51
- - - ">="
51
+ - - "~>"
52
52
  - !ruby/object:Gem::Version
53
- version: '0'
53
+ version: '0.1'
54
54
  type: :runtime
55
55
  prerelease: false
56
56
  version_requirements: !ruby/object:Gem::Requirement
57
57
  requirements:
58
- - - ">="
58
+ - - "~>"
59
59
  - !ruby/object:Gem::Version
60
- version: '0'
60
+ version: '0.1'
61
61
  - !ruby/object:Gem::Dependency
62
62
  name: csvbuilder-importer
63
63
  requirement: !ruby/object:Gem::Requirement
64
64
  requirements:
65
- - - ">="
65
+ - - "~>"
66
66
  - !ruby/object:Gem::Version
67
- version: '0'
67
+ version: '0.1'
68
68
  type: :runtime
69
69
  prerelease: false
70
70
  version_requirements: !ruby/object:Gem::Requirement
71
71
  requirements:
72
- - - ">="
72
+ - - "~>"
73
73
  - !ruby/object:Gem::Version
74
- version: '0'
74
+ version: '0.1'
75
75
  description: Help handle CSVs in a more efficient way
76
76
  email:
77
77
  - joel.azemar@gmail.com
@@ -99,7 +99,6 @@ files:
99
99
  - lib/csvbuilder/dynamic/columns/.DS_Store
100
100
  - lib/csvbuilder/dynamic/columns/importer.rb
101
101
  - lib/csvbuilder/dynamic/columns/importer/concerns/import/dynamic_columns.rb
102
- - lib/csvbuilder/dynamic/columns/importer/internal/dynamic_column_attribute_base.rb
103
102
  - lib/csvbuilder/dynamic/columns/importer/internal/import/dynamic_column_attribute.rb
104
103
  - lib/csvbuilder/dynamic/columns/importer/public/import.rb
105
104
  - lib/csvbuilder/dynamic/columns/importer/version.rb
@@ -1,44 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "csvbuilder/core/internal/attribute_base"
4
- require "csvbuilder/dynamic/columns/core/internal/concerns/dynamic_column_shared"
5
-
6
- module Csvbuilder
7
- class DynamicColumnAttributeBase < AttributeBase
8
- include DynamicColumnShared
9
-
10
- def value
11
- @value ||= row_model_class.format_dynamic_column_cells(unformatted_value, column_name, row_model.context)
12
- end
13
-
14
- def formatted_cells
15
- source_cells.map do |cell|
16
- row_model_class.format_cell(cell, column_name, row_model.context)
17
- end
18
- end
19
-
20
- protected
21
-
22
- def process_cell_method_name
23
- self.class.process_cell_method_name(column_name)
24
- end
25
-
26
- # Calls the process_cell to return the value of a Attribute given the args
27
- def call_process_cell(*args)
28
- row_model.public_send(process_cell_method_name, *args)
29
- end
30
-
31
- class << self
32
- def process_cell_method_name(column_name)
33
- column_name.to_s.singularize.to_sym
34
- end
35
-
36
- # define a method to process each cell of the attribute method
37
- # process_cell = one cell
38
- # attribute_method = many cells = [process_cell(), process_cell()...]
39
- def define_process_cell(row_model_class, column_name, &block)
40
- row_model_class.define_proxy_method(process_cell_method_name(column_name), &block)
41
- end
42
- end
43
- end
44
- end