array_transform 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +10 -0
- data/Gemfile.lock +1 -1
- data/README.md +0 -17
- data/lib/array_transform.rb +0 -2
- data/lib/array_transform/concerns/callable.rb +0 -108
- data/lib/array_transform/operations/add_index_column.rb +0 -5
- data/lib/array_transform/operations/copy_column.rb +0 -8
- data/lib/array_transform/operations/join_with_lookup.rb +5 -7
- data/lib/array_transform/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c57bfcf0be433080cc910278e3bda5a38781dcc8
|
4
|
+
data.tar.gz: abbb2dc11abff401b46ea8335a4157fa84fe4503
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fd0df6edbdc025db7c16cb51e75410828319eb466d5ac55039bf36f195c5d335de29838d507e3a31bf6271e816cc3cef16e5021894e909ce843ad0032fe6b761
|
7
|
+
data.tar.gz: a618260d70b43048033b684739eb92950cbae0512aecd83803426ef46c0f56e05f3599f9f9e771e221b38b4f3ffc1348a52e8df068444b1432fc45a093afa228
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
### 0.1.1 / 2018-11-14
|
2
|
+
|
3
|
+
* Bug fixes
|
4
|
+
* Fixed bug where join with lookup operation used wrong data structure for lookup of join column index.
|
5
|
+
* Fixed join with lookup operation to work with join on a lookup column in any position (not just the first position).
|
6
|
+
|
7
|
+
|
8
|
+
### 0.1.0 / 2018-11-14
|
9
|
+
|
10
|
+
Initial Release.
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,20 +1,3 @@
|
|
1
|
-
# TODO before commit
|
2
|
-
|
3
|
-
* update assertions to match error messages
|
4
|
-
* change copy column to leverage add column (?)
|
5
|
-
* Error handling strategy
|
6
|
-
|
7
|
-
# TODO
|
8
|
-
|
9
|
-
* Add Code Climate badge
|
10
|
-
* Add CI badge
|
11
|
-
* Add DSL
|
12
|
-
* Update readme
|
13
|
-
* Add merge columns operation
|
14
|
-
* Add split column operation
|
15
|
-
* Add copy rows operation
|
16
|
-
* Add append rows operation
|
17
|
-
|
18
1
|
# ArrayTransform
|
19
2
|
|
20
3
|
[![Build Status](https://travis-ci.com/Scrimmage/array_transform.svg?token=4X3FUNyi2mcNDmPpLxLJ&branch=master)](https://travis-ci.com/Scrimmage/array_transform)
|
data/lib/array_transform.rb
CHANGED
@@ -10,12 +10,6 @@ module ArrayTransform::Callable
|
|
10
10
|
module Callable
|
11
11
|
def call
|
12
12
|
super
|
13
|
-
# catch :halt do
|
14
|
-
# super
|
15
|
-
# super.tap do
|
16
|
-
# success unless result_specified?
|
17
|
-
# end
|
18
|
-
# end
|
19
13
|
end
|
20
14
|
end
|
21
15
|
|
@@ -27,106 +21,4 @@ module ArrayTransform::Callable
|
|
27
21
|
end
|
28
22
|
end
|
29
23
|
|
30
|
-
# # Indicates whether the call failed
|
31
|
-
# def failed?
|
32
|
-
# !success?
|
33
|
-
# end
|
34
|
-
|
35
|
-
# # Indicates whether the call called success or failure
|
36
|
-
# def result_specified?
|
37
|
-
# defined?(@success)
|
38
|
-
# end
|
39
|
-
|
40
|
-
# # Mark the call as successful.
|
41
|
-
# def success
|
42
|
-
# @success = true
|
43
|
-
# end
|
44
|
-
|
45
|
-
# # Indicates if the call was successful
|
46
|
-
# def success?
|
47
|
-
# !!@success
|
48
|
-
# end
|
49
|
-
|
50
24
|
end
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
# module UseCase
|
56
|
-
|
57
|
-
# def self.included(base)
|
58
|
-
# base.class_eval do
|
59
|
-
# prepend Perform
|
60
|
-
# extend ClassMethods
|
61
|
-
# include Virtus.model(strict: true, required: false)
|
62
|
-
# include ActiveModel::Validations
|
63
|
-
# end
|
64
|
-
# end
|
65
|
-
|
66
|
-
# module Perform
|
67
|
-
# # Executes use case logic
|
68
|
-
# #
|
69
|
-
# # Use cases must implement this method. Assumes success if failure is not called.
|
70
|
-
# def perform
|
71
|
-
# catch :halt do
|
72
|
-
# super.tap do
|
73
|
-
# success unless result_specified?
|
74
|
-
# end
|
75
|
-
# end
|
76
|
-
# end
|
77
|
-
# end
|
78
|
-
|
79
|
-
# module ClassMethods
|
80
|
-
# # Executes and returns the use case
|
81
|
-
# #
|
82
|
-
# # A use case object is instantiated with the supplied
|
83
|
-
# # arguments, perform is called and the object is returned.
|
84
|
-
# def perform(*args, &block)
|
85
|
-
# new(*args, &block).tap do |use_case|
|
86
|
-
# use_case.perform
|
87
|
-
# end
|
88
|
-
# end
|
89
|
-
# end
|
90
|
-
|
91
|
-
# attr_accessor :error_category, :error_key, :upstream_use_case
|
92
|
-
|
93
|
-
# # Mark the use case as failed.
|
94
|
-
# def failure
|
95
|
-
# @success = false
|
96
|
-
# end
|
97
|
-
|
98
|
-
# # Mark the use case as failed and exits the use case.
|
99
|
-
# def failure!(message = nil)
|
100
|
-
# failure
|
101
|
-
# throw :halt
|
102
|
-
# end
|
103
|
-
|
104
|
-
# # Block invoked only if use case failed.
|
105
|
-
# def on_failure(&block)
|
106
|
-
# yield(self) if failed?
|
107
|
-
# self
|
108
|
-
# end
|
109
|
-
|
110
|
-
# # Block invoked only if use case succeeded.
|
111
|
-
# def on_success(&block)
|
112
|
-
# yield(self) if success?
|
113
|
-
# self
|
114
|
-
# end
|
115
|
-
|
116
|
-
# # Add errors to the provided use case and mark it as failed.
|
117
|
-
# def propagate_failure!(use_case)
|
118
|
-
# if failed?
|
119
|
-
# use_case.upstream_use_case = self
|
120
|
-
# use_case.errors.add(:base, "UseCase #{self.class.name} failed: #{system_error_messages_string}")
|
121
|
-
# use_case.error_key = error_key
|
122
|
-
# use_case.failure!
|
123
|
-
# end
|
124
|
-
# self
|
125
|
-
# end
|
126
|
-
|
127
|
-
# # Halts execution of the use case if validation fails.
|
128
|
-
# def validate!
|
129
|
-
# failure! unless valid?
|
130
|
-
# end
|
131
|
-
|
132
|
-
# end
|
@@ -3,11 +3,6 @@ module ArrayTransform::Operations
|
|
3
3
|
class AddIndexColumn
|
4
4
|
include ArrayTransform::Callable
|
5
5
|
|
6
|
-
# TODO: take a custom number generator?
|
7
|
-
# TODO: support before/after (before_column_header, after_column_header)
|
8
|
-
# [1, 2, 3].insert(1, 4)
|
9
|
-
# => [1, 4, 2, 3]
|
10
|
-
|
11
6
|
def initialize(
|
12
7
|
new_column_header: nil,
|
13
8
|
data:,
|
@@ -35,14 +35,6 @@ module ArrayTransform::Operations
|
|
35
35
|
end
|
36
36
|
|
37
37
|
def copy_column
|
38
|
-
# compare with performance of:
|
39
|
-
#
|
40
|
-
# column_index && AddColumn.call(
|
41
|
-
# cell_operation: -> (row_index) { data[row_index][column_index] },
|
42
|
-
# data: data,
|
43
|
-
# new_column_header: new_column_header
|
44
|
-
# )
|
45
|
-
|
46
38
|
column_index && data.each do |row|
|
47
39
|
row << row[column_index]
|
48
40
|
end
|
@@ -9,7 +9,7 @@ module ArrayTransform::Operations
|
|
9
9
|
data:,
|
10
10
|
lookup_data:,
|
11
11
|
lookup_column_header: nil,
|
12
|
-
lookup_column_index: nil,
|
12
|
+
lookup_column_index: nil,
|
13
13
|
lookup_default: nil
|
14
14
|
)
|
15
15
|
@column_header = column_header
|
@@ -42,10 +42,10 @@ module ArrayTransform::Operations
|
|
42
42
|
end
|
43
43
|
|
44
44
|
def index_lookup_data
|
45
|
-
# TODO: check for dup keys
|
46
45
|
@lookup_by_key = lookup_data.inject({}) { |map, row|
|
47
|
-
map
|
48
|
-
|
46
|
+
map.tap {
|
47
|
+
map[row[lookup_column_index]] = row.dup.tap { |row_copy| row_copy.delete_at(lookup_column_index) }
|
48
|
+
}
|
49
49
|
}
|
50
50
|
end
|
51
51
|
|
@@ -61,7 +61,7 @@ module ArrayTransform::Operations
|
|
61
61
|
end
|
62
62
|
|
63
63
|
def lookup_column_header_index
|
64
|
-
|
64
|
+
lookup_data[0] && lookup_data[0].index(lookup_column_header)
|
65
65
|
end
|
66
66
|
|
67
67
|
def lookup_default
|
@@ -77,8 +77,6 @@ module ArrayTransform::Operations
|
|
77
77
|
raise(ArgumentError, "can only specify one of :lookup_column_index or :lookup_column_header")
|
78
78
|
end
|
79
79
|
|
80
|
-
# TODO: lookup data must have at least two columns?
|
81
|
-
|
82
80
|
if @lookup_default && lookup_data[0] && @lookup_default.count != lookup_data[0].count - 1
|
83
81
|
raise(ArgumentError, "lookup_default must have exactly #{lookup_data[0].count - 1} columns")
|
84
82
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: array_transform
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matthew Chadwick
|
@@ -78,6 +78,7 @@ files:
|
|
78
78
|
- ".gitignore"
|
79
79
|
- ".rspec"
|
80
80
|
- ".travis.yml"
|
81
|
+
- CHANGELOG.md
|
81
82
|
- CODE_OF_CONDUCT.md
|
82
83
|
- Gemfile
|
83
84
|
- Gemfile.lock
|