realize 1.2.0 → 1.3.0
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 +4 -4
- data/.rubocop.yml +1 -0
- data/CHANGELOG.md +11 -4
- data/README.md +2 -0
- data/lib/realize.rb +1 -0
- data/lib/realize/format/string_template.rb +38 -0
- data/lib/realize/format/substring.rb +44 -0
- data/lib/realize/logical/switch.rb +1 -1
- data/lib/realize/transformers.rb +4 -0
- data/lib/realize/version.rb +1 -1
- data/realize.gemspec +2 -1
- metadata +20 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0d7bccc32a2837daee77ec8bcdda00975744c90e0ac08f62f5dbfcaf338dfd91
|
4
|
+
data.tar.gz: aa23c2077287abe225dc2c4b7aa3a2bec7a405bdfd4011ce375d7aed64ac5f56
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e1201c0671253238b656904b713482db1b53b1f720c36821b87618fd6d0ace49314eda6773080ccb3ed27fca50d8cb68f822547d9d631ff8529f437e7babdba5
|
7
|
+
data.tar.gz: aadc039cccfdcae68d14b7902e854e14078ea2a674d7c4e84cc2f16c2f1e54f6f1cc1568a408676b726b581a5f80004861d44f751a350eb340d1bd995f02d3fe
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,11 +1,18 @@
|
|
1
|
+
# 1.3.0 (November 4th, 2020)
|
2
|
+
|
3
|
+
New Transformers:
|
4
|
+
|
5
|
+
* r/format/string_template
|
6
|
+
* r/format/substring
|
7
|
+
|
1
8
|
# 1.2.0 (October 6th, 2020)
|
2
9
|
|
3
10
|
New Transformers:
|
4
11
|
|
5
|
-
*
|
6
|
-
*
|
7
|
-
*
|
8
|
-
*
|
12
|
+
* r/type/boolean
|
13
|
+
* r/type/string
|
14
|
+
* r/value/now
|
15
|
+
* r/value/uuid
|
9
16
|
|
10
17
|
# 1.1.1 (September 9th, 2020)
|
11
18
|
|
data/README.md
CHANGED
@@ -79,6 +79,8 @@ Here is a list of each built-in transformer, their options, and what their funct
|
|
79
79
|
* **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
80
|
* **r/format/remove_whitespace** []: Removes all whitespace from the incoming value.
|
81
81
|
* **r/format/string_replace** [original, replacement]: Replaces all occurrences of the configured original value with the replacement value.
|
82
|
+
* **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.
|
83
|
+
* **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"
|
82
84
|
|
83
85
|
#### Logical Transformers
|
84
86
|
|
data/lib/realize.rb
CHANGED
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Realize
|
4
|
+
class Format
|
5
|
+
# Use an expression as a template and string interpolate it using the Stringento library.
|
6
|
+
# Stringento also uses Objectable to provide (optional) key-path notation for handling
|
7
|
+
# nested objects.
|
8
|
+
# For more information see underlying libraries:
|
9
|
+
# * Stringento: https://github.com/bluemarblepayroll/stringento
|
10
|
+
# * Objectable: https://github.com/bluemarblepayroll/objectable
|
11
|
+
class StringTemplate
|
12
|
+
acts_as_hashable
|
13
|
+
|
14
|
+
DEFAULT_SEPARATOR = '.'
|
15
|
+
|
16
|
+
attr_reader :expression, :resolver, :use_record
|
17
|
+
|
18
|
+
def initialize(expression: '', separator: DEFAULT_SEPARATOR, use_record: false)
|
19
|
+
@expression = expression.to_s
|
20
|
+
@resolver = Objectable.resolver(separator: separator)
|
21
|
+
@use_record = use_record || false
|
22
|
+
|
23
|
+
freeze
|
24
|
+
end
|
25
|
+
|
26
|
+
def transform(_resolver, value, _time, record)
|
27
|
+
input = use_record ? record : value
|
28
|
+
|
29
|
+
Stringento.evaluate(expression, input, resolver: self)
|
30
|
+
end
|
31
|
+
|
32
|
+
# For Stringento consumption
|
33
|
+
def resolve(value, input)
|
34
|
+
resolver.get(input, value)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Realize
|
4
|
+
class Format
|
5
|
+
# Cut a string using a range (start and end index). You can also choose whether you wish the
|
6
|
+
# range selection to be inclusive (default) or exclusive.
|
7
|
+
#
|
8
|
+
# Examples using the string: '012-345-6789'
|
9
|
+
#
|
10
|
+
# Exclusive vs. Inclusive
|
11
|
+
#
|
12
|
+
# [start_index: 4, end_index: 6, exclusive: false] => '345'
|
13
|
+
# [start_index: 4, end_index: 6, exclusive: true] => '34'
|
14
|
+
#
|
15
|
+
# Default Values / Omitted Options
|
16
|
+
#
|
17
|
+
# [end_index: 6] => '012-345'
|
18
|
+
# [start_index: 4] => '345-6789'
|
19
|
+
class Substring
|
20
|
+
acts_as_hashable
|
21
|
+
|
22
|
+
DEFAULT_END_INDEX = -1
|
23
|
+
DEFAULT_START_INDEX = 0
|
24
|
+
|
25
|
+
attr_reader :end_index, :exclusive, :start_index
|
26
|
+
|
27
|
+
def initialize(
|
28
|
+
end_index: DEFAULT_END_INDEX,
|
29
|
+
exclusive: false,
|
30
|
+
start_index: DEFAULT_START_INDEX
|
31
|
+
)
|
32
|
+
@end_index = end_index.to_i
|
33
|
+
@exclusive = exclusive || false
|
34
|
+
@start_index = start_index.to_i
|
35
|
+
|
36
|
+
freeze
|
37
|
+
end
|
38
|
+
|
39
|
+
def transform(_resolver, value, _time, _record)
|
40
|
+
exclusive ? value.to_s[start_index...end_index] : value.to_s[start_index..end_index]
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -14,7 +14,7 @@ module Realize
|
|
14
14
|
|
15
15
|
attr_reader :cases, :default_transformers, :key
|
16
16
|
|
17
|
-
def initialize(cases: [], default_transformers: []
|
17
|
+
def initialize(key:, cases: [], default_transformers: [])
|
18
18
|
raise ArgumentError, 'key is required' if key.to_s.empty?
|
19
19
|
|
20
20
|
@cases = Case.array(cases)
|
data/lib/realize/transformers.rb
CHANGED
@@ -13,6 +13,8 @@ require_relative 'filter/inactive'
|
|
13
13
|
require_relative 'format/date'
|
14
14
|
require_relative 'format/remove_whitespace'
|
15
15
|
require_relative 'format/string_replace'
|
16
|
+
require_relative 'format/string_template'
|
17
|
+
require_relative 'format/substring'
|
16
18
|
|
17
19
|
require_relative 'logical/switch'
|
18
20
|
|
@@ -49,6 +51,8 @@ module Realize
|
|
49
51
|
register 'r/format/date', Format::Date
|
50
52
|
register 'r/format/remove_whitespace', Format::RemoveWhitespace
|
51
53
|
register 'r/format/string_replace', Format::StringReplace
|
54
|
+
register 'r/format/string_template', Format::StringTemplate
|
55
|
+
register 'r/format/substring', Format::Substring
|
52
56
|
|
53
57
|
register 'r/logical/switch', Logical::Switch
|
54
58
|
|
data/lib/realize/version.rb
CHANGED
data/realize.gemspec
CHANGED
@@ -30,12 +30,13 @@ Gem::Specification.new do |s|
|
|
30
30
|
|
31
31
|
s.add_dependency('acts_as_hashable', '~>1', '>=1.2.0')
|
32
32
|
s.add_dependency('objectable', '~>1')
|
33
|
+
s.add_dependency('stringento', '~>2.1')
|
33
34
|
|
34
35
|
s.add_development_dependency('guard-rspec', '~>4.7')
|
35
36
|
s.add_development_dependency('pry', '~>0')
|
36
37
|
s.add_development_dependency('rake', '~> 13')
|
37
38
|
s.add_development_dependency('rspec')
|
38
|
-
s.add_development_dependency('rubocop', '~>
|
39
|
+
s.add_development_dependency('rubocop', '~>1.1')
|
39
40
|
s.add_development_dependency('simplecov', '~>0.17.0')
|
40
41
|
s.add_development_dependency('simplecov-console', '~>0.6.0')
|
41
42
|
end
|
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.3.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-
|
12
|
+
date: 2020-11-04 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: acts_as_hashable
|
@@ -45,6 +45,20 @@ dependencies:
|
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '1'
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: stringento
|
50
|
+
requirement: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '2.1'
|
55
|
+
type: :runtime
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '2.1'
|
48
62
|
- !ruby/object:Gem::Dependency
|
49
63
|
name: guard-rspec
|
50
64
|
requirement: !ruby/object:Gem::Requirement
|
@@ -107,14 +121,14 @@ dependencies:
|
|
107
121
|
requirements:
|
108
122
|
- - "~>"
|
109
123
|
- !ruby/object:Gem::Version
|
110
|
-
version:
|
124
|
+
version: '1.1'
|
111
125
|
type: :development
|
112
126
|
prerelease: false
|
113
127
|
version_requirements: !ruby/object:Gem::Requirement
|
114
128
|
requirements:
|
115
129
|
- - "~>"
|
116
130
|
- !ruby/object:Gem::Version
|
117
|
-
version:
|
131
|
+
version: '1.1'
|
118
132
|
- !ruby/object:Gem::Dependency
|
119
133
|
name: simplecov
|
120
134
|
requirement: !ruby/object:Gem::Requirement
|
@@ -179,6 +193,8 @@ files:
|
|
179
193
|
- lib/realize/format/date.rb
|
180
194
|
- lib/realize/format/remove_whitespace.rb
|
181
195
|
- lib/realize/format/string_replace.rb
|
196
|
+
- lib/realize/format/string_template.rb
|
197
|
+
- lib/realize/format/substring.rb
|
182
198
|
- lib/realize/logical/switch.rb
|
183
199
|
- lib/realize/logical/switch/case.rb
|
184
200
|
- lib/realize/pipeline.rb
|