realize 1.4.0 → 1.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +11 -0
- data/README.md +9 -1
- data/lib/realize.rb +1 -0
- data/lib/realize/file/basename.rb +32 -0
- data/lib/realize/file/extname.rb +22 -0
- data/lib/realize/format/pad.rb +61 -0
- data/lib/realize/format/sha256.rb +49 -0
- data/lib/realize/format/split.rb +33 -0
- data/lib/realize/transformers.rb +14 -0
- data/lib/realize/type/array.rb +36 -0
- data/lib/realize/version.rb +1 -1
- metadata +8 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f6decbc7d163ec927dbb7927ac09aee8d5df5b4de3d44e4ea233959bd1456276
|
4
|
+
data.tar.gz: b4c96da12cbc56d66a50f9396a4e66e3f97dbb035a62d31c29532030c7ee3e3b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e24dffe48d39646bb6e631000c03cb0480ac539d368008ca49d38528696b4b8b37f61fdf2524a9b7c308ec10707b16d6d3966948a4ca0b0be4603e1aa0834dca
|
7
|
+
data.tar.gz: f1d2105f0d009d0520edcd846e9f0b6e00bed4816f07498495a9a51ad849fd1d4a527af122e7c8cc17a6aadaaf101d22aa7f3db36037b895cf7a3b8fa33a33ff
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Realize
|
2
2
|
|
3
|
-
[![Gem Version](https://badge.fury.io/rb/realize.svg)](https://badge.fury.io/rb/realize) [![Build Status](https://travis-ci.
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/realize.svg)](https://badge.fury.io/rb/realize) [![Build Status](https://travis-ci.com/bluemarblepayroll/realize.svg?branch=master)](https://travis-ci.com/bluemarblepayroll/realize) [![Maintainability](https://api.codeclimate.com/v1/badges/115f0c5a1d0a4cce7230/maintainability)](https://codeclimate.com/github/bluemarblepayroll/realize/maintainability) [![Test Coverage](https://api.codeclimate.com/v1/badges/115f0c5a1d0a4cce7230/test_coverage)](https://codeclimate.com/github/bluemarblepayroll/realize/test_coverage) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
|
4
4
|
|
5
5
|
This library provides a pluggable and configurable data transformation framework. The general use-case is:
|
6
6
|
|
@@ -67,6 +67,10 @@ Here is a list of each built-in transformer, their options, and what their funct
|
|
67
67
|
* **r/collection/last** []: Takes an array (or coerces value to an array) and returns the value at the last index position.
|
68
68
|
* **r/collection/sort** [key, direction]: Takes an array (or coerces value to an array) and sort it either ascending or descending by some defined key's value.
|
69
69
|
|
70
|
+
#### File-based Transformers
|
71
|
+
|
72
|
+
* **r/file/basename** [suffix]: Return the filename and extension. If suffix is provided then it will be stripped from the end. If '.*' is passed as the suffix then any extension will be ignored.
|
73
|
+
* **r/file/extname** [suffix]: Return the extension for value.
|
70
74
|
#### Filtering Transformers
|
71
75
|
|
72
76
|
* **r/filter/by_key_record_value** [key, value]: Takes an array (or coerces value to an array) and selects only the records that match the key's value. In this case the value is derived off of the main record.
|
@@ -78,7 +82,10 @@ Here is a list of each built-in transformer, their options, and what their funct
|
|
78
82
|
|
79
83
|
* **r/format/date** [input_format, output_format]: Parses the incoming value into a Time object using the configured input_format and outputs it as formatted by the configured output_format.
|
80
84
|
* **r/format/lowercase** []: Calls `#to_s.downcase` on the value so the returned value is guaranteed to be a lower-cased string.
|
85
|
+
* **r/format/pad** [length, side, with]: Pad a string value with a specified 'with' value (defaults to blank space) up until the passed in length is reached. The 'side' option can be used to specify whether the padding should occur to the left or right side of the value.
|
81
86
|
* **r/format/remove_whitespace** []: Removes all whitespace from the incoming value.
|
87
|
+
* **r/format/sha256** [encoding_format]: Convert the value into a SHA256 encoded string. The encoding_format will be hex by default but can also be configured to use base64.
|
88
|
+
* **r/format/split** [by]: Take a string value and split it on the specified 'by' value. By default, it will be split on a blank space.
|
82
89
|
* **r/format/string_replace** [original, replacement]: Replaces all occurrences of the configured original value with the replacement value.
|
83
90
|
* **r/format/string_template** [expression, separator, use_record]: String interpolate an expression using either the record or passed in value. Nested objects can be handled (i.e. key paths like dot-notation) by passing in a separator.
|
84
91
|
* **r/format/substring** [start_index, end_index, exclusive]: Cut a string in a given range. All options are optional. If a start_index is not provided, the beginning of the string is used. If no end_index is specified then the end of the string is used. If exclusive is set to true then the last index position will not be included. For example: "hellofriend" with a start_index of 0, an end_index of 5, and exclusive as true would yield: "hello". If exclusive was false then it would yield "hellof"
|
@@ -90,6 +97,7 @@ Here is a list of each built-in transformer, their options, and what their funct
|
|
90
97
|
|
91
98
|
#### Type Transformers
|
92
99
|
|
100
|
+
* **r/type/array** [nullable]: Ensure the value is an array by calling Kernel#Array on the value.
|
93
101
|
* **r/type/boolean** [nullable]: Returns `true` if the input is 'truthy', `false` if not. By default nullable is false, which means a nil input will return false. Changing this to true will return nil if nil is passed in. A 'truthy' value is defined as matching: true, t, yes, y, or 1 (case-insensitive).
|
94
102
|
* **r/type/string** [nullable]: Calls `#to_s` on the value so the returned value is guaranteed to be a string type.
|
95
103
|
|
data/lib/realize.rb
CHANGED
@@ -0,0 +1,32 @@
|
|
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 Realize
|
11
|
+
class File
|
12
|
+
# Takes the value and strips out the directory. Suffix is provided as an option which strips
|
13
|
+
# out the extension (last period and beyond). If '.*' is passed in as the suffix then any
|
14
|
+
# extension will be stripped. Note that files with multiple extensions will only have their
|
15
|
+
# last extesion removed.
|
16
|
+
class Basename
|
17
|
+
acts_as_hashable
|
18
|
+
|
19
|
+
attr_reader :suffix
|
20
|
+
|
21
|
+
def initialize(suffix: '')
|
22
|
+
@suffix = suffix.to_s
|
23
|
+
|
24
|
+
freeze
|
25
|
+
end
|
26
|
+
|
27
|
+
def transform(_resolver, value, _time, _record)
|
28
|
+
::File.basename(value.to_s, suffix)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,22 @@
|
|
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 Realize
|
11
|
+
class File
|
12
|
+
# Extract the file extension from the value. If the value has multiple extensions then
|
13
|
+
# only the last one will be returned.
|
14
|
+
class Extname
|
15
|
+
acts_as_hashable
|
16
|
+
|
17
|
+
def transform(_resolver, value, _time, _record)
|
18
|
+
::File.extname(value.to_s)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,61 @@
|
|
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 Realize
|
11
|
+
class Format
|
12
|
+
# Pad a string value with a specified 'with' value (defaults to blank space) up until the
|
13
|
+
# passed in length is reached. The 'side' option can be used to specify whether the
|
14
|
+
# padding should occur to the left or right side of the value.
|
15
|
+
# Examples:
|
16
|
+
# 'ABC' + [length: 10, side: 'left', with: '123'] => '1231231ABC'
|
17
|
+
# 'ABC' + [length: 10, side: 'right, with: '123'] => 'ABC1231231'
|
18
|
+
#
|
19
|
+
# If length is not specified or is less than the actual value's length then no padding
|
20
|
+
# will occur.
|
21
|
+
class Pad
|
22
|
+
acts_as_hashable
|
23
|
+
|
24
|
+
module Side
|
25
|
+
LEFT = :left
|
26
|
+
RIGHT = :right
|
27
|
+
end
|
28
|
+
include Side
|
29
|
+
|
30
|
+
DEFAULT_SIDE = LEFT
|
31
|
+
DEFAULT_WITH = ' '
|
32
|
+
|
33
|
+
attr_reader :length, :side, :with
|
34
|
+
|
35
|
+
def initialize(length: nil, side: LEFT, with: DEFAULT_WITH)
|
36
|
+
@length = length ? length.to_i : nil
|
37
|
+
@side = Side.const_get(side.to_s.upcase.to_sym)
|
38
|
+
@with = with.to_s
|
39
|
+
|
40
|
+
freeze
|
41
|
+
end
|
42
|
+
|
43
|
+
def transform(_resolver, value, _time, _record)
|
44
|
+
return value unless length
|
45
|
+
|
46
|
+
value.to_s.send(just_method, length, with)
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
|
51
|
+
def just_method
|
52
|
+
case side
|
53
|
+
when LEFT
|
54
|
+
:rjust
|
55
|
+
when RIGHT
|
56
|
+
:ljust
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,49 @@
|
|
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 Realize
|
11
|
+
class Format
|
12
|
+
# Convert the value into a SHA256 encoded string. There are two main encoding formats:
|
13
|
+
# hex or base64. By default, the value will be hexidecimal encoded.
|
14
|
+
class Sha256
|
15
|
+
acts_as_hashable
|
16
|
+
|
17
|
+
module EncodingFormat
|
18
|
+
HEX = :hex
|
19
|
+
BASE64 = :base64
|
20
|
+
end
|
21
|
+
include EncodingFormat
|
22
|
+
|
23
|
+
DEFAULT_ENCODING_FORMAT = HEX
|
24
|
+
|
25
|
+
attr_reader :encoding_format
|
26
|
+
|
27
|
+
def initialize(encoding_format: DEFAULT_ENCODING_FORMAT)
|
28
|
+
@encoding_format = EncodingFormat.const_get(encoding_format.to_s.upcase.to_sym)
|
29
|
+
|
30
|
+
freeze
|
31
|
+
end
|
32
|
+
|
33
|
+
def transform(_resolver, value, _time, _record)
|
34
|
+
Digest::SHA256.send(sha_method, value.to_s)
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def sha_method
|
40
|
+
case encoding_format
|
41
|
+
when HEX
|
42
|
+
:hexdigest
|
43
|
+
when BASE64
|
44
|
+
:base64digest
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,33 @@
|
|
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 Realize
|
11
|
+
class Format
|
12
|
+
# Take a string value and split it on the specified 'by' value. By default, it will be
|
13
|
+
# split on a blank space. For example: '123 456 789' would yield ['123', '456', '789'].
|
14
|
+
# If the value is not a string then it will be converted to a string by calling #to_s on it.
|
15
|
+
class Split
|
16
|
+
acts_as_hashable
|
17
|
+
|
18
|
+
DEFAULT_BY = ' '
|
19
|
+
|
20
|
+
attr_reader :by
|
21
|
+
|
22
|
+
def initialize(by: DEFAULT_BY)
|
23
|
+
@by = by.to_s
|
24
|
+
|
25
|
+
freeze
|
26
|
+
end
|
27
|
+
|
28
|
+
def transform(_resolver, value, _time, _record)
|
29
|
+
value.to_s.split(by)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/lib/realize/transformers.rb
CHANGED
@@ -12,6 +12,9 @@ require_relative 'collection/first'
|
|
12
12
|
require_relative 'collection/last'
|
13
13
|
require_relative 'collection/sort'
|
14
14
|
|
15
|
+
require_relative 'file/basename'
|
16
|
+
require_relative 'file/extname'
|
17
|
+
|
15
18
|
require_relative 'filter/by_key_record_value'
|
16
19
|
require_relative 'filter/by_key_value'
|
17
20
|
require_relative 'filter/by_key_value_presence'
|
@@ -19,7 +22,10 @@ require_relative 'filter/inactive'
|
|
19
22
|
|
20
23
|
require_relative 'format/date'
|
21
24
|
require_relative 'format/lowercase'
|
25
|
+
require_relative 'format/pad'
|
22
26
|
require_relative 'format/remove_whitespace'
|
27
|
+
require_relative 'format/sha256'
|
28
|
+
require_relative 'format/split'
|
23
29
|
require_relative 'format/string_replace'
|
24
30
|
require_relative 'format/string_template'
|
25
31
|
require_relative 'format/substring'
|
@@ -27,6 +33,7 @@ require_relative 'format/uppercase'
|
|
27
33
|
|
28
34
|
require_relative 'logical/switch'
|
29
35
|
|
36
|
+
require_relative 'type/array'
|
30
37
|
require_relative 'type/boolean'
|
31
38
|
require_relative 'type/string'
|
32
39
|
|
@@ -52,6 +59,9 @@ module Realize
|
|
52
59
|
register 'r/collection/last', Collection::Last
|
53
60
|
register 'r/collection/sort', Collection::Sort
|
54
61
|
|
62
|
+
register 'r/file/basename', File::Basename
|
63
|
+
register 'r/file/extname', File::Extname
|
64
|
+
|
55
65
|
register 'r/filter/by_key_record_value', Filter::ByKeyRecordValue
|
56
66
|
register 'r/filter/by_key_value', Filter::ByKeyValue
|
57
67
|
register 'r/filter/by_key_value_presence', Filter::ByKeyValuePresence
|
@@ -59,7 +69,10 @@ module Realize
|
|
59
69
|
|
60
70
|
register 'r/format/date', Format::Date
|
61
71
|
register 'r/format/lowercase', Format::Lowercase
|
72
|
+
register 'r/format/pad', Format::Pad
|
62
73
|
register 'r/format/remove_whitespace', Format::RemoveWhitespace
|
74
|
+
register 'r/format/sha256', Format::Sha256
|
75
|
+
register 'r/format/split', Format::Split
|
63
76
|
register 'r/format/string_replace', Format::StringReplace
|
64
77
|
register 'r/format/string_template', Format::StringTemplate
|
65
78
|
register 'r/format/substring', Format::Substring
|
@@ -67,6 +80,7 @@ module Realize
|
|
67
80
|
|
68
81
|
register 'r/logical/switch', Logical::Switch
|
69
82
|
|
83
|
+
register 'r/type/array', Type::Array
|
70
84
|
register 'r/type/boolean', Type::Boolean
|
71
85
|
register 'r/type/string', Type::String
|
72
86
|
|
@@ -0,0 +1,36 @@
|
|
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 'base'
|
11
|
+
|
12
|
+
module Realize
|
13
|
+
class Type
|
14
|
+
# Ensure the value is an array by calling Kernel#Array on the value. If the value is a hash
|
15
|
+
# then it will ensure the hash data structure is preserved and placed within the array.
|
16
|
+
# Normally calling Array(hash) would yield an array of key-value pair arrays. For our
|
17
|
+
# pipeline we generally treat hashes as "record-like" objects, so we need to ensure
|
18
|
+
# we keep it in tact.
|
19
|
+
#
|
20
|
+
# This does not mean other data types do not suffer from Kernel#Array
|
21
|
+
# converting it to something unexpected. For example, passing in a Time object would yield
|
22
|
+
# an array of parts:
|
23
|
+
# Array(Time.now) => [2, 59, 10, 21, 11, 2020, 6, 326, false, "CST"]
|
24
|
+
#
|
25
|
+
# See: https://ruby-doc.org/core-2.7.2/Kernel.html#method-i-Array for more information.
|
26
|
+
class Array < Base
|
27
|
+
include Arrays
|
28
|
+
|
29
|
+
def transform(_resolver, value, _time, _record)
|
30
|
+
return nil if nullable && value.nil?
|
31
|
+
|
32
|
+
array(value)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/lib/realize/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: realize
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matthew Ruggio
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2020-11-
|
12
|
+
date: 2020-11-24 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: acts_as_hashable
|
@@ -186,13 +186,18 @@ files:
|
|
186
186
|
- lib/realize/collection/last.rb
|
187
187
|
- lib/realize/collection/sort.rb
|
188
188
|
- lib/realize/collection/sort/direction.rb
|
189
|
+
- lib/realize/file/basename.rb
|
190
|
+
- lib/realize/file/extname.rb
|
189
191
|
- lib/realize/filter/by_key_record_value.rb
|
190
192
|
- lib/realize/filter/by_key_value.rb
|
191
193
|
- lib/realize/filter/by_key_value_presence.rb
|
192
194
|
- lib/realize/filter/inactive.rb
|
193
195
|
- lib/realize/format/date.rb
|
194
196
|
- lib/realize/format/lowercase.rb
|
197
|
+
- lib/realize/format/pad.rb
|
195
198
|
- lib/realize/format/remove_whitespace.rb
|
199
|
+
- lib/realize/format/sha256.rb
|
200
|
+
- lib/realize/format/split.rb
|
196
201
|
- lib/realize/format/string_replace.rb
|
197
202
|
- lib/realize/format/string_template.rb
|
198
203
|
- lib/realize/format/substring.rb
|
@@ -201,6 +206,7 @@ files:
|
|
201
206
|
- lib/realize/logical/switch/case.rb
|
202
207
|
- lib/realize/pipeline.rb
|
203
208
|
- lib/realize/transformers.rb
|
209
|
+
- lib/realize/type/array.rb
|
204
210
|
- lib/realize/type/base.rb
|
205
211
|
- lib/realize/type/boolean.rb
|
206
212
|
- lib/realize/type/string.rb
|