portable 1.0.0.pre.alpha.3 → 1.0.0

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: 32da634ac58591d5130ab01ddb7e6953144f663b563fdce844817473db370bde
4
- data.tar.gz: c7b6ded1144b5cdb46ab702a5d23480d4a778b4bfa134c21f4ae884bf1ecc220
3
+ metadata.gz: 563f9b0e89cfa8fecd2346faa4448a88919ee8188c08ddfbcb0dfe0033acf0b6
4
+ data.tar.gz: 3f3d82c6a9539e93028cf781b72bdd42d3bd753ccb0a6a2018286a3afc71e20f
5
5
  SHA512:
6
- metadata.gz: b3cbe61597e5ea310d8084cafcaea7cf75476d969e5ad833ee140397d92cfe9d7c2baf2f5d930754f1870dd1f1b757f91562d79bfdee74e870670f21c981712f
7
- data.tar.gz: 3a101c3f5c3467060cfe7b237efec41e51435d0fe0941a753d6e6b03ba776b99f8aad1845d62015e6cf54a6bbd464902414f8bd0128d7c3cbc8682afd4d084bc
6
+ metadata.gz: 511a1e5ccea009b86e5c4f8838945c6d6cadf150709f5f31e6d6163b59431d05a0a2604ecc4686529f8aa505857f55607de4a74510348b20d52c71ec23b559af
7
+ data.tar.gz: 93c0c1a1480d961fedfe4c46a909b0ecb25958bfcfb55c8dd0575d7318c7575176b0347588c543d1830b22938a22a473283ce78a109378d9926f423a0848c41b
@@ -20,7 +20,7 @@ Metrics/MethodLength:
20
20
  Max: 30
21
21
 
22
22
  Metrics/AbcSize:
23
- Max: 17
23
+ Max: 20
24
24
 
25
25
  Metrics/ClassLength:
26
26
  Max: 125
@@ -2,8 +2,6 @@ env:
2
2
  global:
3
3
  - CC_TEST_REPORTER_ID=f40f0e6f9946420b05b247f1640b2f5fcef181ca86659a2e71c747f790fcecdd
4
4
  language: ruby
5
- services:
6
- - mysql
7
5
  rvm:
8
6
  # Build on the latest stable of all supported Rubies (https://www.ruby-lang.org/en/downloads/):
9
7
  - 2.5.8
@@ -1,3 +1,3 @@
1
- # 1.0.0 (TBD)
1
+ # 1.0.0 (August 25th, 2020)
2
2
 
3
3
  Initial implementation.
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at oss@bluemarblepayroll.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/README.md CHANGED
@@ -35,7 +35,7 @@ patients = [
35
35
  data_provider = Portable::Data::Provider.new(
36
36
  data_sources: {
37
37
  data_rows: patients,
38
- fields: %i[first last dob]
38
+ keys: %i[first last dob]
39
39
  }
40
40
  )
41
41
  ````
@@ -50,7 +50,7 @@ document = nil # or {} or Portable::Document.new
50
50
 
51
51
  The above document says I would like a document with one sheet, and since I did not provide a data_table specification, I would like all the fields emitted from the data source.
52
52
 
53
- Combining a document + writer + data provider yields a set of documents (it may be more than one if the writer does not know how to write intra-file sheets, i.e. CSV files.)
53
+ Combining a document + writer + data provider yields a set of documents. It may emit more than one file if the writer does not know how to write intra-file sheets (i.e. CSV files).
54
54
 
55
55
  ````ruby
56
56
  writer = Portable::Writers::Csv.new(document)
@@ -72,6 +72,18 @@ This library uses Realize under the hood, so you have the option of configuring
72
72
  Let's expand our CSV example above with different headers and date formatting:
73
73
 
74
74
  ````ruby
75
+ patients = [
76
+ { first: 'Marky', last: 'Mark', dob: '2000-04-05' },
77
+ { first: 'Frank', last: 'Rizzo', dob: '1930-09-22' }
78
+ ]
79
+
80
+ data_provider = Portable::Data::Provider.new(
81
+ data_sources: {
82
+ data_rows: patients,
83
+ keys: %i[first last dob]
84
+ }
85
+ )
86
+
75
87
  document = {
76
88
  sheets: [
77
89
  {
@@ -101,14 +113,20 @@ document = {
101
113
  }
102
114
  ]
103
115
  }
116
+
117
+ writer = Portable::Writers::Csv.new(document)
118
+ name = File.join('tmp', 'patients.csv')
119
+ written = writer.write!(filename: name, data_provider: data_provider)
104
120
  ````
105
121
 
106
122
  Executing it the same way would now yield a different CSV file:
107
123
 
124
+ ````
108
125
  First Name | Last Name | Date of Birth
109
126
  ---------- | --------- | -------------
110
127
  Marky | Mark | 04/05/2000
111
128
  Frank | Rizzo | 09/22/1930
129
+ ````
112
130
 
113
131
  Realize is also [pluggable](https://github.com/bluemarblepayroll/realize#plugging-in-transformers), so you are able to create your own and plug them directly into Realize.
114
132
 
@@ -120,7 +138,7 @@ Each writer can choose how and which options to support.
120
138
 
121
139
  The following options are available for customizing CSV documents:
122
140
 
123
- * byte_order_mark: (optional, default is nothing): This option will write out a byte order mark identifying the encoding for the file. This is useful for ensuring applications like Microsoft Excel open CSV files properly. See Portable::Modeling::ByteOrderMark constants for acceptable values.
141
+ * byte_order_mark: (optional, default is nothing): This option will write out a [byte order mark](https://en.wikipedia.org/wiki/Byte_order_mark) identifying the endianess for the file. This is useful for ensuring applications like Microsoft Excel open CSV files properly. See Portable::Modeling::ByteOrderMark constants for acceptable values.
124
142
 
125
143
  ### Static Header/Footer Rows
126
144
 
@@ -135,7 +153,7 @@ patients = [
135
153
  data_provider = Portable::Data::Provider.new(
136
154
  data_sources: {
137
155
  data_rows: patients,
138
- fields: %i[first last dob],
156
+ keys: %i[first last dob],
139
157
  header_rows: [
140
158
  %w[FIRST_START LAST_START DOB_START]
141
159
  ],
@@ -160,6 +178,10 @@ document = {
160
178
  }
161
179
  ]
162
180
  }
181
+
182
+ writer = Portable::Writers::Csv.new(document)
183
+ name = File.join('tmp', 'patients.csv')
184
+ written = writer.write!(filename: name, data_provider: data_provider)
163
185
  ````
164
186
 
165
187
  Using this document configuration would yield a CSV with four "header rows" at the top, one "data table header row", two data rows, and one "footer row". This is not easily illustrated in Markdown, but this would be the result:
@@ -169,10 +191,12 @@ Run Date | 04/05/2000
169
191
  Run By | Hops the Bunny
170
192
 
171
193
  BEGIN
172
- First Name | Last Name | Date of Birth
173
- ---------- | --------- | -------------
174
- Marky | Mark | 04/05/2000
175
- Frank | Rizzo | 09/22/1930
194
+ FIRST_START | LAST_START | DOB_START
195
+ first | last | dob
196
+ ----------- | ---------- | -------------
197
+ Marky | Mark | 2000-04-05
198
+ Frank | Rizzo | 1930-09-22
199
+ FIRST_END | LAST_END | DOB_END
176
200
  END
177
201
  ````
178
202
 
@@ -8,6 +8,7 @@
8
8
  #
9
9
 
10
10
  require 'acts_as_hashable'
11
+ require 'benchmark'
11
12
  require 'csv'
12
13
  require 'fileutils'
13
14
  require 'forwardable'
@@ -16,7 +17,7 @@ require 'realize'
16
17
  require 'time'
17
18
 
18
19
  # Shared modules/classes
19
- require_relative 'portable/uniqueness'
20
+ require_relative 'portable/util'
20
21
 
21
22
  # Main implementation points
22
23
  require_relative 'portable/data'
@@ -14,7 +14,8 @@ module Portable
14
14
  # Container of data sources that is inputted into a writer alongside a document.
15
15
  # It contains all the data sources the writer will use to render a document.
16
16
  class Provider
17
- include Uniqueness
17
+ include Util::Pivotable
18
+ include Util::Uniqueness
18
19
  acts_as_hashable
19
20
 
20
21
  def initialize(data_sources: [])
@@ -26,19 +27,16 @@ module Portable
26
27
  freeze
27
28
  end
28
29
 
30
+ # Fail hard if we cannot identify which data source to use. This should help prevent
31
+ # possible configuration issues (i.e. typos.)
29
32
  def data_source(name)
30
- data_sources_by_name.fetch(name.to_s, Source.new)
33
+ data_sources_by_name[name.to_s] ||
34
+ raise(ArgumentError, "data source: '#{name}' cannot be found.")
31
35
  end
32
36
 
33
37
  private
34
38
 
35
39
  attr_reader :data_sources_by_name
36
-
37
- def pivot_by_name(data_sources)
38
- data_sources.each_with_object({}) do |data_source, memo|
39
- memo[data_source.name] = data_source
40
- end
41
- end
42
40
  end
43
41
  end
44
42
  end
@@ -19,17 +19,17 @@ module Portable
19
19
  attr_reader :header_rows,
20
20
  :footer_rows,
21
21
  :data_rows,
22
- :fields,
22
+ :keys,
23
23
  :name
24
24
 
25
25
  # Individial header and footer rows are arrays, while individual data_rows is an object
26
26
  # like a hash, Struct, OpenStruct, or really any PORO.
27
- def initialize(name: '', header_rows: [], footer_rows: [], data_rows: [], fields: [])
27
+ def initialize(name: '', header_rows: [], footer_rows: [], data_rows: [], keys: [])
28
28
  @name = name.to_s
29
29
  @header_rows = header_rows || []
30
30
  @footer_rows = footer_rows || []
31
31
  @data_rows = data_rows || []
32
- @fields = fields || []
32
+ @keys = keys || []
33
33
 
34
34
  freeze
35
35
  end
@@ -13,19 +13,37 @@ require_relative 'modeling/sheet'
13
13
  module Portable
14
14
  # Top-level object model for a renderable document.
15
15
  class Document
16
- include Uniqueness
16
+ include Util::Pivotable
17
+ include Util::Uniqueness
17
18
  acts_as_hashable
18
19
 
19
- attr_reader :sheets, :options
20
+ attr_reader :options
20
21
 
21
22
  def initialize(sheets: [], options: {})
22
- @sheets = Modeling::Sheet.array(sheets)
23
- @sheets << Modeling::Sheet.new if @sheets.empty?
24
- @options = Modeling::Options.make(options)
25
-
26
- assert_no_duplicate_names(@sheets)
23
+ @sheets_by_name = make_unique_sheets_by_name(sheets)
24
+ @options = Modeling::Options.make(options, nullable: false)
27
25
 
28
26
  freeze
29
27
  end
28
+
29
+ def sheet(name)
30
+ sheets_by_name.fetch(name.to_s)
31
+ end
32
+
33
+ def sheets
34
+ sheets_by_name.values
35
+ end
36
+
37
+ private
38
+
39
+ attr_reader :sheets_by_name
40
+
41
+ def make_unique_sheets_by_name(sheets)
42
+ sheets = Modeling::Sheet.array(sheets)
43
+ sheets << Modeling::Sheet.new if sheets.empty?
44
+
45
+ assert_no_duplicate_names(sheets)
46
+ pivot_by_name(sheets)
47
+ end
30
48
  end
31
49
  end
@@ -16,10 +16,15 @@ module Portable
16
16
  class DataTable
17
17
  acts_as_hashable
18
18
 
19
- attr_reader :columns
19
+ attr_reader :auto, :columns, :include_headers
20
20
 
21
- def initialize(columns: [])
22
- @columns = Column.array(columns)
21
+ alias include_headers? include_headers
22
+ alias auto? auto
23
+
24
+ def initialize(auto: true, columns: [], include_headers: true)
25
+ @auto = auto || false
26
+ @columns = Column.array(columns)
27
+ @include_headers = include_headers || false
23
28
 
24
29
  freeze
25
30
  end
@@ -17,31 +17,47 @@ module Portable
17
17
  # one file.
18
18
  class Sheet
19
19
  acts_as_hashable
20
+ extend Forwardable
20
21
 
21
- attr_reader :data_table,
22
+ def_delegators :data_table,
23
+ :auto?,
24
+ :columns,
25
+ :include_headers?
26
+
27
+ attr_reader :data_source_name,
28
+ :data_table,
22
29
  :footer_rows,
23
30
  :header_rows,
24
- :name,
25
- :include_headers
31
+ :name
26
32
 
27
33
  def initialize(
34
+ data_source_name: '',
28
35
  data_table: nil,
29
36
  footer_rows: [],
30
37
  header_rows: [],
31
- name: '',
32
- include_headers: true
38
+ name: ''
33
39
  )
34
- @name = name.to_s
35
- @data_table = DataTable.make(data_table)
36
- @footer_rows = footer_rows || []
37
- @header_rows = header_rows || []
38
- @include_headers = include_headers || false
40
+ @data_source_name = decide_data_source_name(data_source_name, name)
41
+ @name = name.to_s
42
+ @data_table = DataTable.make(data_table, nullable: false)
43
+ @footer_rows = footer_rows || []
44
+ @header_rows = header_rows || []
39
45
 
40
46
  freeze
41
47
  end
42
48
 
43
- def include_headers?
44
- include_headers
49
+ private
50
+
51
+ # Use exact name if possible, if not then use the sheet name or else use the
52
+ # "default" one (noted by a blank name).
53
+ def decide_data_source_name(data_source_name, sheet_name)
54
+ if !data_source_name.to_s.empty?
55
+ data_source_name.to_s
56
+ elsif !sheet_name.to_s.empty?
57
+ sheet_name.to_s
58
+ else
59
+ ''
60
+ end
45
61
  end
46
62
  end
47
63
  end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ #
4
+ # Copyright (c) 2020-present, Blue Marble Payroll, LLC
5
+ #
6
+ # This source code is licensed under the MIT license found in the
7
+ # LICENSE file in the root directory of this source tree.
8
+ #
9
+
10
+ module Portable
11
+ module Rendering
12
+ class Column # :nodoc: all
13
+ extend Forwardable
14
+
15
+ attr_reader :column, :pipeline
16
+
17
+ def_delegators :column, :header
18
+
19
+ def_delegators :pipeline, :transform
20
+
21
+ def initialize(column, resolver: Objectable.resolver)
22
+ raise ArgumentError, 'column is required' unless column
23
+
24
+ @column = column
25
+ @pipeline = Realize::Pipeline.new(column.transformers, resolver: resolver)
26
+
27
+ freeze
28
+ end
29
+ end
30
+ end
31
+ end
@@ -7,34 +7,37 @@
7
7
  # LICENSE file in the root directory of this source tree.
8
8
  #
9
9
 
10
+ require_relative 'column'
11
+
10
12
  module Portable
11
13
  module Rendering
12
14
  # Internal intermediary class that knows how to combine columns specification
13
15
  # instances with their respective Realize pipelines.
14
16
  class Row # :nodoc: all
15
- attr_reader :column_pipelines
17
+ attr_reader :columns, :resolver
16
18
 
17
19
  def initialize(columns, resolver: Objectable.resolver)
18
- @column_pipelines = columns.each_with_object({}) do |column, memo|
19
- memo[column] = Realize::Pipeline.new(column.transformers, resolver: resolver)
20
- end
20
+ @resolver = resolver
21
+ @columns = columns.map { |column| Column.new(column, resolver: resolver) }
21
22
 
22
23
  freeze
23
24
  end
24
25
 
25
26
  def render(object, time)
26
- column_pipelines.each_with_object({}) do |(column, pipeline), memo|
27
- memo[column.header] = pipeline.transform(object, time)
28
- end
29
- end
30
-
31
- def columns
32
- column_pipelines.keys
27
+ columns.map { |column| column.transform(object, time) }
33
28
  end
34
29
 
35
30
  def headers
36
31
  columns.map(&:header)
37
32
  end
33
+
34
+ def model_columns
35
+ columns.map(&:column)
36
+ end
37
+
38
+ def merge(other)
39
+ self.class.new(model_columns + other.model_columns, resolver: resolver)
40
+ end
38
41
  end
39
42
  end
40
43
  end
@@ -21,27 +21,32 @@ module Portable
21
21
  @resolver = resolver
22
22
 
23
23
  @row_renderers = @document.sheets.each_with_object({}) do |sheet, memo|
24
- next unless sheet.data_table
25
-
26
- memo[sheet.name] = Row.new(sheet.data_table.columns, resolver: resolver)
24
+ memo[sheet.name] = Row.new(sheet.columns, resolver: resolver)
27
25
  end
28
26
 
29
27
  freeze
30
28
  end
31
29
 
32
- def row_renderer(sheet_name, fields)
33
- row_renderers.fetch(sheet_name, dynamic_row_renderer(fields))
30
+ def row_renderer(sheet_name, keys)
31
+ sheet = document.sheet(sheet_name)
32
+ row_renderer = row_renderers.fetch(sheet_name.to_s)
33
+
34
+ return row_renderer unless sheet.auto?
35
+
36
+ dynamic_row_renderer(keys).merge(row_renderer)
34
37
  end
35
38
 
36
39
  private
37
40
 
38
41
  attr_reader :row_renderers
39
42
 
40
- def dynamic_row_renderer(fields)
41
- fields = (fields || []).map { |f| { header: f.to_s } }
42
- columns = Modeling::Column.array(fields)
43
+ def fields_to_columns(keys)
44
+ key_objects = (keys || []).map { |f| { header: f.to_s } }
45
+ Modeling::Column.array(key_objects)
46
+ end
43
47
 
44
- Row.new(columns, resolver: resolver)
48
+ def dynamic_row_renderer(keys)
49
+ Row.new(fields_to_columns(keys), resolver: resolver)
45
50
  end
46
51
  end
47
52
  end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ #
4
+ # Copyright (c) 2020-present, Blue Marble Payroll, LLC
5
+ #
6
+ # This source code is licensed under the MIT license found in the
7
+ # LICENSE file in the root directory of this source tree.
8
+ #
9
+
10
+ require_relative 'util/pivotable'
11
+ require_relative 'util/uniqueness'
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ #
4
+ # Copyright (c) 2020-present, Blue Marble Payroll, LLC
5
+ #
6
+ # This source code is licensed under the MIT license found in the
7
+ # LICENSE file in the root directory of this source tree.
8
+ #
9
+
10
+ module Portable
11
+ module Util # :nodoc: all
12
+ # Mixes in helpers for asserting uniqueness across collections
13
+ module Pivotable
14
+ def pivot_by_name(array)
15
+ array.each_with_object({}) { |object, memo| memo[object.name] = object }
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ #
4
+ # Copyright (c) 2020-present, Blue Marble Payroll, LLC
5
+ #
6
+ # This source code is licensed under the MIT license found in the
7
+ # LICENSE file in the root directory of this source tree.
8
+ #
9
+
10
+ module Portable
11
+ module Util # :nodoc: all
12
+ # Mixes in helpers for asserting uniqueness across collections
13
+ module Uniqueness
14
+ class DuplicateNameError < StandardError; end
15
+
16
+ def assert_no_duplicate_names(array)
17
+ names = array.map { |a| a.name.downcase }
18
+
19
+ return if names.uniq.length == array.length
20
+
21
+ raise DuplicateNameError, "cannot contain duplicate names (case insensitive): #{names}"
22
+ end
23
+ end
24
+ end
25
+ end
@@ -8,5 +8,5 @@
8
8
  #
9
9
 
10
10
  module Portable
11
- VERSION = '1.0.0-alpha.3'
11
+ VERSION = '1.0.0'
12
12
  end
@@ -20,6 +20,14 @@ module Portable
20
20
 
21
21
  freeze
22
22
  end
23
+
24
+ private
25
+
26
+ def ensure_directory_exists(filename)
27
+ path = File.dirname(filename)
28
+
29
+ FileUtils.mkdir_p(path) unless File.exist?(path)
30
+ end
23
31
  end
24
32
  end
25
33
  end
@@ -8,6 +8,7 @@
8
8
  #
9
9
 
10
10
  require_relative 'base'
11
+ require_relative 'result'
11
12
 
12
13
  module Portable
13
14
  module Writers
@@ -18,16 +19,18 @@ module Portable
18
19
 
19
20
  ensure_directory_exists(filename)
20
21
 
21
- sheet_filenames = extrapolate_filenames(filename)
22
+ sheet_filenames = extrapolate_filenames(filename, document.sheets.length)
22
23
 
23
- document.sheets.each do |sheet|
24
- data_source = data_provider.data_source(sheet.name)
25
- sheet_filename = sheet_filenames[sheet.name]
24
+ document.sheets.map.with_index do |sheet, index|
25
+ data_source = data_provider.data_source(sheet.data_source_name)
26
+ sheet_filename = sheet_filenames[index]
26
27
 
27
- write_sheet(sheet_filename, sheet, data_source, time)
28
- end
28
+ time_in_seconds = Benchmark.measure do
29
+ write_sheet(sheet_filename, sheet, data_source, time)
30
+ end.real
29
31
 
30
- sheet_filenames.values
32
+ Result.new(sheet_filename, time_in_seconds)
33
+ end
31
34
  end
32
35
 
33
36
  private
@@ -49,12 +52,12 @@ module Portable
49
52
  end
50
53
 
51
54
  def write_data_table(csv, sheet, data_source, time)
52
- row_renderer = sheet_renderer.row_renderer(sheet.name, data_source.fields)
55
+ row_renderer = sheet_renderer.row_renderer(sheet.name, data_source.keys)
53
56
 
54
57
  csv << row_renderer.headers if sheet.include_headers?
55
58
 
56
59
  data_source.data_rows.each do |row|
57
- csv << row_renderer.render(row, time).values
60
+ csv << row_renderer.render(row, time)
58
61
  end
59
62
  end
60
63
 
@@ -64,27 +67,17 @@ module Portable
64
67
  sheet.footer_rows.each { |row| csv << row }
65
68
  end
66
69
 
67
- def ensure_directory_exists(filename)
68
- path = File.dirname(filename)
69
-
70
- FileUtils.mkdir_p(path) unless File.exist?(path)
71
- end
72
-
73
- def extrapolate_filenames(filename)
74
- index = 0
70
+ def extrapolate_filenames(filename, count)
75
71
  dir = File.dirname(filename)
76
72
  ext = File.extname(filename)
77
73
  basename = File.basename(filename, ext)
78
74
 
79
- document.sheets.each_with_object({}) do |sheet, memo|
80
- memo[sheet.name] =
81
- if index.positive?
82
- File.join(dir, "#{basename}.#{index}#{ext}")
83
- else
84
- filename
85
- end
86
-
87
- index += 1
75
+ (0..count).map do |index|
76
+ if index.positive?
77
+ File.join(dir, "#{basename}.#{index}#{ext}")
78
+ else
79
+ filename
80
+ end
88
81
  end
89
82
  end
90
83
  end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ #
4
+ # Copyright (c) 2020-present, Blue Marble Payroll, LLC
5
+ #
6
+ # This source code is licensed under the MIT license found in the
7
+ # LICENSE file in the root directory of this source tree.
8
+ #
9
+
10
+ module Portable
11
+ module Writers
12
+ # Result return object from a Writer#write! call.
13
+ class Result
14
+ attr_reader :filename, :time_in_seconds
15
+
16
+ def initialize(filename, time_in_seconds)
17
+ @filename = filename
18
+ @time_in_seconds = time_in_seconds
19
+
20
+ freeze
21
+ end
22
+ end
23
+ end
24
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: portable
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.pre.alpha.3
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthew Ruggio
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-08-07 00:00:00.000000000 Z
11
+ date: 2020-08-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: acts_as_hashable
@@ -165,6 +165,7 @@ files:
165
165
  - ".ruby-version"
166
166
  - ".travis.yml"
167
167
  - CHANGELOG.md
168
+ - CODE_OF_CONDUCT.md
168
169
  - Gemfile
169
170
  - Guardfile
170
171
  - LICENSE
@@ -183,13 +184,17 @@ files:
183
184
  - lib/portable/modeling/options.rb
184
185
  - lib/portable/modeling/sheet.rb
185
186
  - lib/portable/rendering.rb
187
+ - lib/portable/rendering/column.rb
186
188
  - lib/portable/rendering/row.rb
187
189
  - lib/portable/rendering/sheet.rb
188
- - lib/portable/uniqueness.rb
190
+ - lib/portable/util.rb
191
+ - lib/portable/util/pivotable.rb
192
+ - lib/portable/util/uniqueness.rb
189
193
  - lib/portable/version.rb
190
194
  - lib/portable/writers.rb
191
195
  - lib/portable/writers/base.rb
192
196
  - lib/portable/writers/csv.rb
197
+ - lib/portable/writers/result.rb
193
198
  - portable.gemspec
194
199
  homepage: https://github.com/bluemarblepayroll/portable
195
200
  licenses:
@@ -211,9 +216,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
211
216
  version: '2.5'
212
217
  required_rubygems_version: !ruby/object:Gem::Requirement
213
218
  requirements:
214
- - - ">"
219
+ - - ">="
215
220
  - !ruby/object:Gem::Version
216
- version: 1.3.1
221
+ version: '0'
217
222
  requirements: []
218
223
  rubygems_version: 3.0.3
219
224
  signing_key:
@@ -1,23 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- #
4
- # Copyright (c) 2020-present, Blue Marble Payroll, LLC
5
- #
6
- # This source code is licensed under the MIT license found in the
7
- # LICENSE file in the root directory of this source tree.
8
- #
9
-
10
- module Portable
11
- # Mixes in helpers for asserting uniqueness across collections
12
- module Uniqueness
13
- class DuplicateNameError < StandardError; end
14
-
15
- def assert_no_duplicate_names(array)
16
- names = array.map { |a| a.name.downcase }
17
-
18
- return if names.uniq.length == array.length
19
-
20
- raise DuplicateNameError, "cannot contain duplicate names: #{names}"
21
- end
22
- end
23
- end