realize 1.0.0.pre.alpha.2 → 1.1.1

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: 289c0fa13f4421249a59e82ce767881f04bd47bea5d0b3a4eb4db503b37add28
4
- data.tar.gz: f8575e76151f98fc0e34d8fcf4c50231294ffad0f037eb6f276fd1393f8e6cd4
3
+ metadata.gz: e3bd172f76576e00c4765b1a5dead05e5692a0b79ad5e6e3eb2e3b6bb2c1667c
4
+ data.tar.gz: 51c606f8a5d85fe3c5ee893e4acae40f647f60350d0f2a0155af6dee5a0e5eba
5
5
  SHA512:
6
- metadata.gz: cf1f9808bdb3870860155d3eecf6187b4bb9a5b3b4ea755552a125e9a96fb34173d3174d2ba98c5da9aeef00dea520e3d2cf2b2f7821daa4b2d3c6558f8cec21
7
- data.tar.gz: ec3bc0d03c004d8481b4d1d9b690076f9dd48988e9e957cd61c82aac40e77d60401666057dc9484b4ea8d6d116ed781305af49b0dcdf0d2bdfe77583393fc931
6
+ metadata.gz: 9fbd8b77f12fc4054133adb16f1a1e89544ac24fded6bb144d3b2f0e2f20cbb1c87d5261de28d734c8a88a82f8046623b200e836e7983437e0fd506d1baf753d
7
+ data.tar.gz: 43fef7ff265071ae18a0ed5ef8d77e270cfcd939d9fed0cc4c825f78dda7f7d59db88c150731ab34f3f061c9522b6f0d54d593292df4ae23447de79e5b152273
@@ -1,3 +1,13 @@
1
- # 1.0.0 (June 8th, 2020)
1
+ # 1.1.1 (September 9th, 2020)
2
+
3
+ Fixes:
4
+
5
+ * 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.
6
+
7
+ # 1.1.0 (June 24th, 2020)
8
+
9
+ Addition of r/collection/at_index, r/collection/first, and r/collection/last
10
+
11
+ # 1.0.0 (June 9th, 2020)
2
12
 
3
13
  Initial Release, includes 15 initial transformers.
data/README.md CHANGED
@@ -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
@@ -83,12 +86,12 @@ Here is a list of each built-in transformer, their options, and what their funct
83
86
 
84
87
  #### Value-oriented Transformers
85
88
 
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.
89
+ * **r/value/blank** []: Always return a blank string.
90
+ * **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.
91
+ * **r/value/null** []: Always returns null.
92
+ * **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.)
93
+ * **r/value/static** [value]: Always returns a hard-coded value.
94
+ * **r/value/verbatim** []: Default transformer, simply echos back the input.
92
95
 
93
96
  ### Plugging in Transformers
94
97
 
@@ -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
@@ -1,16 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative 'sort/direction'
4
+
3
5
  module Realize
4
6
  class Collection
5
- # Transformer to take an array of oibjects and sort by the given key
7
+ # Transformer to take an array of objects and sort by the given key
6
8
  # and by the given sort direction. Defaulting to ascending.
7
9
  class Sort
8
- module Direction
9
- ASCENDING = 'ASC'
10
- ASC = 'ASC'
11
- DESCENDING = 'DESC'
12
- DESC = 'DESC'
13
- end
14
10
  include Arrays
15
11
  include Direction
16
12
  acts_as_hashable
@@ -1,35 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative 'sort/direction'
4
-
5
3
  module Realize
6
4
  class Collection
7
- # Transformer to take an array of oibjects and sort by the given key
8
- # and by the given sort direction. Defaulting to ascending.
9
5
  class Sort
10
- include Arrays
11
- include Direction
12
- acts_as_hashable
13
-
14
- DEFAULT_ORDER = ASCENDING
15
-
16
- attr_reader :key, :order
17
-
18
- def initialize(key:, order: DEFAULT_ORDER)
19
- raise ArgumentError, 'key is required' if key.to_s.empty?
20
-
21
- @key = key
22
- @order = Direction.const_get(order.to_s.upcase.to_sym)
23
-
24
- freeze
25
- end
26
-
27
- def transform(_resolver, value, _time, _record)
28
- records = array(value)
29
-
30
- sorted = records.sort_by { |hsh| hsh[key.to_sym] }
31
-
32
- order == DESCENDING ? sorted.reverse : sorted
6
+ # Constants describing the possible values of 'direction' for a Sort instance.
7
+ module Direction
8
+ # providing a few different ways to specify.
9
+ ASCENDING = ASC = 'ASC'
10
+ DESCENDING = DESC = 'DESC'
33
11
  end
34
12
  end
35
13
  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,5 +1,8 @@
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'
4
7
  require_relative 'filter/by_key_record_value'
5
8
  require_relative 'filter/by_key_value'
@@ -25,6 +28,9 @@ module Realize
25
28
  acts_as_hashable_factory
26
29
 
27
30
  register '', Value::Verbatim
31
+ register 'r/collection/at_index', Collection::AtIndex
32
+ register 'r/collection/first', Collection::First
33
+ register 'r/collection/last', Collection::Last
28
34
  register 'r/collection/sort', Collection::Sort
29
35
  register 'r/filter/by_key_record_value', Filter::ByKeyRecordValue
30
36
  register 'r/filter/by_key_value', Filter::ByKeyValue
@@ -8,5 +8,5 @@
8
8
  #
9
9
 
10
10
  module Realize
11
- VERSION = '1.0.0-alpha.2'
11
+ VERSION = '1.1.1'
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 = []
@@ -28,7 +28,7 @@ Gem::Specification.new do |s|
28
28
 
29
29
  s.required_ruby_version = '>= 2.5'
30
30
 
31
- s.add_dependency('acts_as_hashable', '=1.2.0.pre.alpha')
31
+ s.add_dependency('acts_as_hashable', '~>1', '>=1.2.0')
32
32
  s.add_dependency('objectable', '~>1')
33
33
 
34
34
  s.add_development_dependency('guard-rspec', '~>4.7')
metadata CHANGED
@@ -1,29 +1,36 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: realize
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.pre.alpha.2
4
+ version: 1.1.1
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-09-09 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: acts_as_hashable
15
16
  requirement: !ruby/object:Gem::Requirement
16
17
  requirements:
17
- - - '='
18
+ - - "~>"
18
19
  - !ruby/object:Gem::Version
19
- version: 1.2.0.pre.alpha
20
+ version: '1'
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 1.2.0
20
24
  type: :runtime
21
25
  prerelease: false
22
26
  version_requirements: !ruby/object:Gem::Requirement
23
27
  requirements:
24
- - - '='
28
+ - - "~>"
25
29
  - !ruby/object:Gem::Version
26
- version: 1.2.0.pre.alpha
30
+ version: '1'
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 1.2.0
27
34
  - !ruby/object:Gem::Dependency
28
35
  name: objectable
29
36
  requirement: !ruby/object:Gem::Requirement
@@ -139,6 +146,7 @@ dependencies:
139
146
  description: " Derive and transform a value using a configuration-first pipeline.\n"
140
147
  email:
141
148
  - mruggio@bluemarblepayroll.com
149
+ - ddewar@bluemarblepayroll.com
142
150
  executables: []
143
151
  extensions: []
144
152
  extra_rdoc_files: []
@@ -159,6 +167,9 @@ files:
159
167
  - exe/.gitkeep
160
168
  - lib/realize.rb
161
169
  - lib/realize/arrays.rb
170
+ - lib/realize/collection/at_index.rb
171
+ - lib/realize/collection/first.rb
172
+ - lib/realize/collection/last.rb
162
173
  - lib/realize/collection/sort.rb
163
174
  - lib/realize/collection/sort/direction.rb
164
175
  - lib/realize/filter/by_key_record_value.rb
@@ -200,9 +211,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
200
211
  version: '2.5'
201
212
  required_rubygems_version: !ruby/object:Gem::Requirement
202
213
  requirements:
203
- - - ">"
214
+ - - ">="
204
215
  - !ruby/object:Gem::Version
205
- version: 1.3.1
216
+ version: '0'
206
217
  requirements: []
207
218
  rubygems_version: 3.0.3
208
219
  signing_key: