realize 1.0.0 → 1.2.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: d5725ecd097c45ce632cd82af3b5c03cd7f54dec0503c007ee28498a2ebe2f0e
4
- data.tar.gz: c6731e9b7f14b3c7109e7a680ba107702dc2c65336e5cea75194f6f61501e796
3
+ metadata.gz: cfdc46e645ec480e88d53d4b68261ce46c2d1db6aff4a7f3a25359e014605246
4
+ data.tar.gz: ab19b4b184c520c12709739a136c789f35a8f9bb1e770ce6c9b9e7b577b6be3c
5
5
  SHA512:
6
- metadata.gz: 1dc9995383fa3a27c3414cd1549871724583c19a1dccbda403b6dc6224927711a4d3309a894ddb9ed0c94587a2d7d37ac870a1fbe9fcc45a017073db39570ce0
7
- data.tar.gz: 2cc2a27d5faa2aa2cd188c94051beaa1cf92acc2e499b1cf3762f667a0e4e27c2f9a750cfd687990cbdfcf52d86ee494278b4062af0ab091aa117b1ab7db035f
6
+ metadata.gz: 801d68a75e3138c5dc5cc713550d799f6cc83caf3247451df3a12735cc407ecc4f10c240bbc58a02480da215484bdcb316c41914b74fe0ad9aaa820d523f97e3
7
+ data.tar.gz: 8b88602a495732c85f5388cf5e9a456e0edb8170e6817947cbf34ec09c33154732f899af70b9608a140dccb57cf8e4c45212b574b7f096a7483a60822b389e6c
@@ -1,3 +1,22 @@
1
+ # 1.2.0 (October 6th, 2020)
2
+
3
+ New Transformers:
4
+
5
+ * b/type/boolean
6
+ * b/type/string
7
+ * b/value/now
8
+ * b/value/uuid
9
+
10
+ # 1.1.1 (September 9th, 2020)
11
+
12
+ Fixes:
13
+
14
+ * Do not leverage #to_datetime even if it is available for date parsing. This removes un-intentional coupling of other libraries into Realize and keeps it based on Ruby standard and core libraries.
15
+
16
+ # 1.1.0 (June 24th, 2020)
17
+
18
+ Addition of r/collection/at_index, r/collection/first, and r/collection/last
19
+
1
20
  # 1.0.0 (June 9th, 2020)
2
21
 
3
22
  Initial Release, includes 15 initial transformers.
data/README.md CHANGED
@@ -13,7 +13,7 @@ It is currently used in production at Blue Marble to power the transformation pi
13
13
  To install through Rubygems:
14
14
 
15
15
  ````
16
- gem install install realize
16
+ gem install realize
17
17
  ````
18
18
 
19
19
  You can also add this to your Gemfile:
@@ -62,6 +62,9 @@ Here is a list of each built-in transformer, their options, and what their funct
62
62
 
63
63
  #### Collection-oriented Transformers
64
64
 
65
+ * **r/collection/at_index** [index]: Takes an array (or coerces value to an array) and returns the value at the given index position.
66
+ * **r/collection/first** []: Takes an array (or coerces value to an array) and returns the value at the first index position.
67
+ * **r/collection/last** []: Takes an array (or coerces value to an array) and returns the value at the last index position.
65
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.
66
69
 
67
70
  #### Filtering Transformers
@@ -81,14 +84,21 @@ Here is a list of each built-in transformer, their options, and what their funct
81
84
 
82
85
  * **r/logical/switch** [cases, default_transformers, key]: Provides a value-based logic branching. If a value matches a specific case, the specific cases transformers will be executed. If it does not match any case then the default_transformers will be executed.
83
86
 
87
+ #### Type Transformers
88
+
89
+ * **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).
90
+ * **r/type/string** []: Calls `#to_s` on the value so the returned value is guaranteed to be a string type.
91
+
84
92
  #### Value-oriented Transformers
85
93
 
86
- * **r/logical/blank** []: Always return a blank string.
87
- * **r/logical/map** [values]: Do a lookup on the value using the `values` hash. If a value is found, then its corresponding value is returned. If it isn't then the input is returned.
88
- * **r/logical/null** []: Always returns null.
89
- * **r/logical/resolve** [key]: Dynamically resolves a value based on the record's key. It uses the [Objectable](https://github.com/bluemarblepayroll/objectable) library by default, which provides some goodies like dot-notation for nested objects and type-insensitivity (works for Ruby objects, hashes, structs, etc.)
90
- * **r/logical/static** [value]: Always returns a hard-coded value.
91
- * **r/logical/verbatim** []: Default transformer, simply echos back the input.
94
+ * **r/value/blank** []: Always return a blank string.
95
+ * **r/value/map** [values]: Do a lookup on the value using the `values` hash. If a value is found, then its corresponding value is returned. If it isn't then the input is returned.
96
+ * **r/value/now** [utc_offset]: Returns a Time object, defaulting to UTC offset. You can optionally pass in a different offset in the FORM: "+/-HH:MM"
97
+ * **r/value/null** []: Always returns null.
98
+ * **r/value/resolve** [key]: Dynamically resolves a value based on the record's key. It uses the [Objectable](https://github.com/bluemarblepayroll/objectable) library by default, which provides some goodies like dot-notation for nested objects and type-insensitivity (works for Ruby objects, hashes, structs, etc.)
99
+ * **r/value/static** [value]: Always returns a hard-coded value.
100
+ * **r/value/uuid** []: Returns a new 36 character UUID (i.e. 6967fec6-bbde-4497-82d9-55ccc7b87cd0)
101
+ * **r/value/verbatim** []: Default transformer, simply echos back the input.
92
102
 
93
103
  ### Plugging in Transformers
94
104
 
@@ -9,6 +9,7 @@
9
9
 
10
10
  require 'acts_as_hashable'
11
11
  require 'objectable'
12
+ require 'securerandom'
12
13
  require 'time'
13
14
 
14
15
  require_relative 'realize/arrays'
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Realize
4
+ class Collection
5
+ # Transformer to get an item of a collection
6
+ class AtIndex
7
+ acts_as_hashable
8
+
9
+ attr_reader :index
10
+
11
+ def initialize(index:)
12
+ raise ArgumentError, 'index is required' if index.to_s.empty?
13
+
14
+ @index = index.to_i
15
+
16
+ freeze
17
+ end
18
+
19
+ def transform(_resolver, value, _time, _record)
20
+ value.is_a?(Array) ? value[index] : value
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Realize
4
+ class Collection
5
+ # Transformer to get the first item of a collection
6
+ class First
7
+ acts_as_hashable
8
+
9
+ def transform(resolver, value, time, record)
10
+ AtIndex.new(index: 0).transform(resolver, value, time, record)
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Realize
4
+ class Collection
5
+ # Transformer to get the last item of a collection
6
+ class Last
7
+ acts_as_hashable
8
+
9
+ def transform(resolver, value, time, record)
10
+ AtIndex.new(index: -1).transform(resolver, value, time, record)
11
+ end
12
+ end
13
+ end
14
+ end
@@ -30,12 +30,10 @@ module Realize
30
30
  return nil if value.to_s.empty?
31
31
 
32
32
  date_time =
33
- if value.respond_to?(:to_datetime)
34
- value.to_datetime
35
- elsif input_format?
33
+ if input_format?
36
34
  DateTime.strptime(value, input_format)
37
35
  else
38
- DateTime.parse(value)
36
+ DateTime.parse(value.to_s)
39
37
  end
40
38
 
41
39
  date_time.strftime(output_format)
@@ -1,19 +1,31 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative 'collection/at_index'
4
+ require_relative 'collection/first'
5
+ require_relative 'collection/last'
3
6
  require_relative 'collection/sort'
7
+
4
8
  require_relative 'filter/by_key_record_value'
5
9
  require_relative 'filter/by_key_value'
6
10
  require_relative 'filter/by_key_value_presence'
7
11
  require_relative 'filter/inactive'
12
+
8
13
  require_relative 'format/date'
9
14
  require_relative 'format/remove_whitespace'
10
15
  require_relative 'format/string_replace'
16
+
11
17
  require_relative 'logical/switch'
18
+
19
+ require_relative 'type/boolean'
20
+ require_relative 'type/string'
21
+
12
22
  require_relative 'value/blank'
13
23
  require_relative 'value/map'
24
+ require_relative 'value/now'
14
25
  require_relative 'value/null'
15
26
  require_relative 'value/resolve'
16
27
  require_relative 'value/static'
28
+ require_relative 'value/uuid'
17
29
  require_relative 'value/verbatim'
18
30
 
19
31
  module Realize
@@ -24,21 +36,32 @@ module Realize
24
36
  class Transformers
25
37
  acts_as_hashable_factory
26
38
 
27
- register '', Value::Verbatim
39
+ register 'r/collection/at_index', Collection::AtIndex
40
+ register 'r/collection/first', Collection::First
41
+ register 'r/collection/last', Collection::Last
28
42
  register 'r/collection/sort', Collection::Sort
43
+
29
44
  register 'r/filter/by_key_record_value', Filter::ByKeyRecordValue
30
45
  register 'r/filter/by_key_value', Filter::ByKeyValue
31
46
  register 'r/filter/by_key_value_presence', Filter::ByKeyValuePresence
32
47
  register 'r/filter/inactive', Filter::Inactive
48
+
33
49
  register 'r/format/date', Format::Date
34
50
  register 'r/format/remove_whitespace', Format::RemoveWhitespace
35
51
  register 'r/format/string_replace', Format::StringReplace
52
+
36
53
  register 'r/logical/switch', Logical::Switch
54
+
55
+ register 'r/type/boolean', Type::Boolean
56
+ register 'r/type/string', Type::String
57
+
37
58
  register 'r/value/blank', Value::Blank
38
59
  register 'r/value/map', Value::Map
60
+ register 'r/value/now', Value::Now
39
61
  register 'r/value/null', Value::Null
40
62
  register 'r/value/resolve', Value::Resolve
41
63
  register 'r/value/static', Value::Static
42
- register 'r/value/verbatim', Value::Verbatim
64
+ register 'r/value/uuid', Value::Uuid
65
+ register 'r/value/verbatim', '', Value::Verbatim
43
66
  end
44
67
  end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Realize
4
+ class Type
5
+ # Convert input into either true, false, or nil.
6
+ # By default nils will return false unless nullable: true is passed in.
7
+ # This transformer is very liberal in its parsing and will return true for:
8
+ # true, 'true', 't', 'TRUE', 'True', 1, '1', 'Y', 'yes', 'Yes', 'YES'
9
+ # All other non-truthy values will evaluate to false, such as:
10
+ # false, 'false', 'f', 'FALSE', 'False', 0, '0', 'N', 'no', 'No', 'NO', {}, [], '',
11
+ # 'abc', 123, :abc, etc...
12
+ class Boolean
13
+ acts_as_hashable
14
+
15
+ attr_reader :nullable
16
+
17
+ def initialize(nullable: false)
18
+ @nullable = nullable || false
19
+ end
20
+
21
+ def transform(_resolver, value, _time, _record)
22
+ if nullable && value.nil?
23
+ nil
24
+ elsif truthy?(value)
25
+ true
26
+ else
27
+ false
28
+ end
29
+ end
30
+
31
+ private
32
+
33
+ def truthy?(value)
34
+ value.to_s.match?(/(true|t|yes|y|1)$/i)
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Realize
4
+ class Type
5
+ # Call #to_s on the value and return result.
6
+ class String
7
+ acts_as_hashable
8
+
9
+ attr_reader :nullable
10
+
11
+ def initialize(nullable: false)
12
+ @nullable = nullable || false
13
+ end
14
+
15
+ def transform(_resolver, value, _time, _record)
16
+ return nil if nullable && value.nil?
17
+
18
+ value.to_s
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Realize
4
+ class Value
5
+ # Return a current Time object.
6
+ class Now
7
+ acts_as_hashable
8
+
9
+ DEFAULT_UTC_OFFSET = '+00:00'
10
+
11
+ attr_reader :utc_offset
12
+
13
+ def initialize(utc_offset: DEFAULT_UTC_OFFSET)
14
+ @utc_offset = utc_offset || DEFAULT_UTC_OFFSET
15
+
16
+ freeze
17
+ end
18
+
19
+ def transform(_resolver, _value, _time, _record)
20
+ Time.now.utc.localtime(utc_offset)
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Realize
4
+ class Value
5
+ # Return a current Time object.
6
+ class Uuid
7
+ acts_as_hashable
8
+
9
+ def transform(_resolver, _value, _time, _record)
10
+ SecureRandom.uuid
11
+ end
12
+ end
13
+ end
14
+ end
@@ -8,5 +8,5 @@
8
8
  #
9
9
 
10
10
  module Realize
11
- VERSION = '1.0.0'
11
+ VERSION = '1.2.0'
12
12
  end
@@ -11,8 +11,8 @@ Gem::Specification.new do |s|
11
11
  Derive and transform a value using a configuration-first pipeline.
12
12
  DESCRIPTION
13
13
 
14
- s.authors = ['Matthew Ruggio']
15
- s.email = ['mruggio@bluemarblepayroll.com']
14
+ s.authors = ['Matthew Ruggio', 'Dan Dewar']
15
+ s.email = ['mruggio@bluemarblepayroll.com', 'ddewar@bluemarblepayroll.com']
16
16
  s.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
17
  s.bindir = 'exe'
18
18
  s.executables = []
metadata CHANGED
@@ -1,14 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: realize
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthew Ruggio
8
+ - Dan Dewar
8
9
  autorequire:
9
10
  bindir: exe
10
11
  cert_chain: []
11
- date: 2020-06-09 00:00:00.000000000 Z
12
+ date: 2020-10-06 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: acts_as_hashable
@@ -145,6 +146,7 @@ dependencies:
145
146
  description: " Derive and transform a value using a configuration-first pipeline.\n"
146
147
  email:
147
148
  - mruggio@bluemarblepayroll.com
149
+ - ddewar@bluemarblepayroll.com
148
150
  executables: []
149
151
  extensions: []
150
152
  extra_rdoc_files: []
@@ -165,6 +167,9 @@ files:
165
167
  - exe/.gitkeep
166
168
  - lib/realize.rb
167
169
  - lib/realize/arrays.rb
170
+ - lib/realize/collection/at_index.rb
171
+ - lib/realize/collection/first.rb
172
+ - lib/realize/collection/last.rb
168
173
  - lib/realize/collection/sort.rb
169
174
  - lib/realize/collection/sort/direction.rb
170
175
  - lib/realize/filter/by_key_record_value.rb
@@ -178,11 +183,15 @@ files:
178
183
  - lib/realize/logical/switch/case.rb
179
184
  - lib/realize/pipeline.rb
180
185
  - lib/realize/transformers.rb
186
+ - lib/realize/type/boolean.rb
187
+ - lib/realize/type/string.rb
181
188
  - lib/realize/value/blank.rb
182
189
  - lib/realize/value/map.rb
190
+ - lib/realize/value/now.rb
183
191
  - lib/realize/value/null.rb
184
192
  - lib/realize/value/resolve.rb
185
193
  - lib/realize/value/static.rb
194
+ - lib/realize/value/uuid.rb
186
195
  - lib/realize/value/verbatim.rb
187
196
  - lib/realize/version.rb
188
197
  - realize.gemspec