csvbuilder-core 0.1.2 → 0.1.3

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: 66d6db396e9e5218f7a22b363d047317e4d2992a38491bc0378b2214b130e27c
4
- data.tar.gz: 5cbd8d0429b26bf6388ef32673e9e23cfbbb91f71a33952da1f5be8a9982adb9
3
+ metadata.gz: e7be65a3637e42b4ec99f9ebc795479ac8b629fa5921fe892784c928ce788789
4
+ data.tar.gz: 65e07ac9fdedb085aa6850ae58cba1d1b530275b4dfe6c39edbb28b3ab8f6db5
5
5
  SHA512:
6
- metadata.gz: c6338d0f2b49f91d63586536abb1f9e021a273ef739925e5dae00350cd4792b8b60ab957bfa7a9bb0a249d156571ee5d00ff115d617caec1a5fa7612632a6cb7
7
- data.tar.gz: 3999ccceef910ee15c10ab438ef93dcce3dfd7b76c22d86053c6d50b32014dd549dc29e28bc211b250ec6fae36e825fa3e1efafa232e76d7731a49be9ee84e8d
6
+ metadata.gz: 0fb1213ba385c60faecc0f4a943ffd71328f215609bf4b876f0c641691f52d6caa545c621ba1b3ebb4df7be6a9a58c51cef2679754786abb90ada1cbd1321aab
7
+ data.tar.gz: e816c1c62f4e22a16d416f82abefbc502c523d2656700140fee941d84a7051e82ab65798dad21eb43e044c0c4e863339e0ae27b2d2a104d205619fce9b2eee66
data/CHANGELOG.md CHANGED
@@ -1,5 +1,33 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.1.3] - 2023-03-03
4
+
5
+ Add Header default formatting
6
+
7
+ ```ruby
8
+ class BasicRowModel
9
+ include Csvbuilder::Model
10
+
11
+ column :alpha
12
+ end
13
+
14
+ BasicRowModel.headers
15
+ # => ["Alpha"]
16
+ ```
17
+
18
+ Basic Proc Capability
19
+
20
+ ```ruby
21
+ class BasicRowModel
22
+ include Csvbuilder::Model
23
+
24
+ column :alpha, header: ->(column_name, context) { "#{context.inspect} #{column_name.to_s.humanize}" }
25
+ end
26
+
27
+ BasicRowModel.headers({ foo: :bar }) }
28
+ # => ["#<OpenStruct foo=:bar> Alpha"] }
29
+ ```
30
+
3
31
  ## [0.1.0] - 2022-12-15
4
32
 
5
33
  - Initial release
data/Gemfile.lock ADDED
@@ -0,0 +1,80 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ csvbuilder-core (0.1.3)
5
+ activesupport (>= 5.2, < 8)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ activesupport (7.0.4)
11
+ concurrent-ruby (~> 1.0, >= 1.0.2)
12
+ i18n (>= 1.6, < 2)
13
+ minitest (>= 5.1)
14
+ tzinfo (~> 2.0)
15
+ ast (2.4.2)
16
+ concurrent-ruby (1.1.10)
17
+ diff-lcs (1.5.0)
18
+ i18n (1.12.0)
19
+ concurrent-ruby (~> 1.0)
20
+ json (2.6.3)
21
+ minitest (5.16.3)
22
+ parallel (1.22.1)
23
+ parser (3.1.3.0)
24
+ ast (~> 2.4.1)
25
+ rainbow (3.1.1)
26
+ rake (13.0.6)
27
+ regexp_parser (2.6.1)
28
+ rexml (3.2.5)
29
+ rspec (3.12.0)
30
+ rspec-core (~> 3.12.0)
31
+ rspec-expectations (~> 3.12.0)
32
+ rspec-mocks (~> 3.12.0)
33
+ rspec-core (3.12.0)
34
+ rspec-support (~> 3.12.0)
35
+ rspec-expectations (3.12.1)
36
+ diff-lcs (>= 1.2.0, < 2.0)
37
+ rspec-support (~> 3.12.0)
38
+ rspec-mocks (3.12.1)
39
+ diff-lcs (>= 1.2.0, < 2.0)
40
+ rspec-support (~> 3.12.0)
41
+ rspec-support (3.12.0)
42
+ rubocop (1.41.1)
43
+ json (~> 2.3)
44
+ parallel (~> 1.10)
45
+ parser (>= 3.1.2.1)
46
+ rainbow (>= 2.2.2, < 4.0)
47
+ regexp_parser (>= 1.8, < 3.0)
48
+ rexml (>= 3.2.5, < 4.0)
49
+ rubocop-ast (>= 1.23.0, < 2.0)
50
+ ruby-progressbar (~> 1.7)
51
+ unicode-display_width (>= 1.4.0, < 3.0)
52
+ rubocop-ast (1.24.0)
53
+ parser (>= 3.1.1.0)
54
+ rubocop-performance (1.15.2)
55
+ rubocop (>= 1.7.0, < 2.0)
56
+ rubocop-ast (>= 0.4.0)
57
+ rubocop-rake (0.6.0)
58
+ rubocop (~> 1.0)
59
+ rubocop-rspec (2.16.0)
60
+ rubocop (~> 1.33)
61
+ ruby-progressbar (1.11.0)
62
+ tzinfo (2.0.5)
63
+ concurrent-ruby (~> 1.0)
64
+ unicode-display_width (2.3.0)
65
+
66
+ PLATFORMS
67
+ arm64-darwin-21
68
+ arm64-darwin-22
69
+
70
+ DEPENDENCIES
71
+ csvbuilder-core!
72
+ rake
73
+ rspec
74
+ rubocop
75
+ rubocop-performance
76
+ rubocop-rake
77
+ rubocop-rspec
78
+
79
+ BUNDLED WITH
80
+ 2.4.2
data/README.md CHANGED
@@ -1,8 +1,12 @@
1
1
  # Csvbuilder::Core
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/core`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ [Csvbuilder::Core](https://github.com/joel/csvbuilder-core) 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 core contains the shared components used and extended by the exporter and the importer. It is the foundation of the gem [csvbuilder](https://github.com/joel/csvbuilder) and carries the library's architecture, and it is not meant to be used alone.
6
+
7
+ See:
8
+ - [Csvbuilder::Exporter](https://github.com/joel/csvbuilder-exporter)
9
+ - [Csvbuilder::Importer](https://github.com/joel/csvbuilder-importer)
6
10
 
7
11
  ## Installation
8
12
 
@@ -14,9 +18,122 @@ If bundler is not being used to manage dependencies, install the gem by executin
14
18
 
15
19
  $ gem install csvbuilder-core
16
20
 
17
- ## Usage
21
+ # Architecture
22
+
23
+ It is organized into three sections, the public, internal and mixins.
24
+
25
+ <img width="215" alt="Screenshot 2022-12-28 at 12 53 59 PM" src="https://user-images.githubusercontent.com/5789/209835572-01d1a7e5-3175-490c-a166-1b9b74908390.png">
26
+
27
+ # Public
28
+
29
+ The public exposes the API meant to be used by the other components. The concrete implementation is mainly lying in the Mixins, though.
30
+
31
+ # Base Attributes
32
+
33
+ It represents a `CSV` row in `Csvbuilder`. At the core, it defines the standard behaviour, and those behaviours are specialized in `Export` and `Import` gems.
34
+
35
+ In `core/concerns/attributes_base`, it exposes three main methods:
36
+
37
+ 1. `original_attributes`
38
+ 2. `formatted_attributes`
39
+ 3. `source_attributes`
40
+
41
+ Those methods are collections called on `Attribute`—for instance, `original_attributes` call `Attribute#value` under the hood for the current row.
42
+
43
+ # Model Attributes
44
+
45
+ In `core/concerns/model/attributes`, we can find the DSL where columns with the options are defined and stored.
46
+
47
+ ```ruby
48
+ class BasicRowModel
49
+ include Csvbuilder::Model
50
+
51
+ column :alpha
52
+ column :beta
53
+ end
54
+ ```
55
+
56
+ It also carries the headers and the two methods helping with the formatting.
57
+
58
+ ```ruby
59
+ class BasicRowModel
60
+ include Csvbuilder::Model
61
+
62
+ class << self
63
+
64
+ # Used by Csvbuilder::AttributeBase#formatted_value
65
+ def format_cell(value, column_name, context)
66
+ "- || * #{column_name} * || -"
67
+ end
68
+
69
+ # Used by Csvbuilder::Model::Header#formatted_header
70
+ def format_header(column_name, context)
71
+ "~ #{column_name} ~"
72
+ end
73
+ end
74
+ end
75
+
76
+ header = "Alpha"
77
+ value = "alpha one"
78
+
79
+ AttributeBase.new.formatted_value
80
+ # => "- || * alpha one * || -"
81
+
82
+ AttributeBase.new.value # It can carry some logic.
83
+ # => "- || * alpha one * || -"
84
+
85
+ AttributeBase.new.source_value # Will be always the raw value
86
+ # => "alpha one"
87
+
88
+ Header.new.formatted_header
89
+ # => ~ Alpha ~
90
+ ```
91
+
92
+ Internally calling respectively:
93
+
94
+ ```ruby
95
+ module Csvbuilder
96
+ module Model
97
+ class Header
98
+
99
+ def formatted_header
100
+ row_model_class.format_header(column_name, context)
101
+ end
102
+
103
+ end
104
+ end
105
+ end
106
+
107
+ ```
108
+
109
+ and
110
+
111
+ ```ruby
112
+ module Csvbuilder
113
+ class AttributeBase
114
+
115
+ def formatted_value
116
+ @formatted_value ||= row_model_class.format_cell(source_value, column_name, row_model.context)
117
+ end
118
+
119
+ end
120
+ end
121
+
122
+ ```
123
+
124
+ # Attribute
125
+
126
+ Represent the cell value.
127
+
128
+ Can be found here: `core/internal/attribute_base`.
129
+
130
+ It can represent the value through the three following methods:
131
+
132
+ 1. `source_value` unchanged value
133
+ 2. `value` often the formatted_value, but some logic can be added.
134
+ 3. `formatted_value`
18
135
 
19
- TODO: Write usage instructions here
136
+ <img width="725" alt="Screenshot 2022-12-28 at 3 23 34 PM" src="https://user-images.githubusercontent.com/5789/209835649-373ebaad-ed53-420d-8a7a-1b93c782d066.png">
20
137
 
21
138
  ## Development
22
139
 
@@ -26,7 +143,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
26
143
 
27
144
  ## Contributing
28
145
 
29
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/csvbuilder-core. 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-core/blob/main/CODE_OF_CONDUCT.md).
146
+ Bug reports and pull requests are welcome on GitHub at https://github.com/joel/csvbuilder-core. 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-core/blob/main/CODE_OF_CONDUCT.md).
30
147
 
31
148
  ## License
32
149
 
@@ -13,10 +13,23 @@ module Csvbuilder
13
13
  @row_model = row_model
14
14
  end
15
15
 
16
+ # @return [Object] the value with formatting applied
16
17
  def formatted_value
17
18
  @formatted_value ||= row_model_class.format_cell(source_value, column_name, row_model.context)
18
19
  end
19
20
 
21
+ # @return [Object] the value
22
+ def value
23
+ raise NotImplementedError
24
+ end
25
+
26
+ # @return [Object] the unchanged value from the source
27
+ def source_value
28
+ raise NotImplementedError
29
+ end
30
+
31
+ protected
32
+
20
33
  def row_model_class
21
34
  row_model.class
22
35
  end
@@ -16,11 +16,18 @@ module Csvbuilder
16
16
  end
17
17
 
18
18
  def value
19
- options[:header] || formatted_header
19
+ case options[:header]
20
+ when Proc
21
+ return options[:header].call(column_name, context)
22
+ when String
23
+ return options[:header]
24
+ end
25
+
26
+ formatted_header(column_name.to_s.humanize)
20
27
  end
21
28
 
22
- def formatted_header
23
- row_model_class.format_header(column_name, context)
29
+ def formatted_header(header_name)
30
+ row_model_class.format_header(header_name, context)
24
31
  end
25
32
  end
26
33
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Csvbuilder
4
4
  module Core
5
- VERSION = "0.1.2"
5
+ VERSION = "0.1.3"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: csvbuilder-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
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-20 00:00:00.000000000 Z
11
+ date: 2023-03-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -43,6 +43,7 @@ files:
43
43
  - CHANGELOG.md
44
44
  - CODE_OF_CONDUCT.md
45
45
  - Gemfile
46
+ - Gemfile.lock
46
47
  - LICENSE.txt
47
48
  - README.md
48
49
  - Rakefile
@@ -83,7 +84,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
83
84
  - !ruby/object:Gem::Version
84
85
  version: '0'
85
86
  requirements: []
86
- rubygems_version: 3.3.22
87
+ rubygems_version: 3.4.6
87
88
  signing_key:
88
89
  specification_version: 4
89
90
  summary: Csvbuilder Core contain the shared components of Csvbuilder