necromancer 0.5.1 → 0.6.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/CHANGELOG.md +6 -0
- data/lib/necromancer.rb +4 -3
- data/lib/necromancer/context.rb +4 -4
- data/lib/necromancer/conversion_target.rb +5 -5
- data/lib/necromancer/conversions.rb +10 -10
- data/lib/necromancer/converter.rb +1 -1
- data/lib/necromancer/converters/array.rb +6 -6
- data/lib/necromancer/converters/boolean.rb +2 -2
- data/lib/necromancer/converters/date_time.rb +4 -4
- data/lib/necromancer/converters/numeric.rb +7 -7
- data/lib/necromancer/converters/range.rb +6 -6
- data/lib/necromancer/null_converter.rb +1 -1
- data/lib/necromancer/version.rb +1 -1
- metadata +9 -77
- data/Rakefile +0 -8
- data/necromancer.gemspec +0 -34
- data/spec/spec_helper.rb +0 -53
- data/spec/unit/can_spec.rb +0 -9
- data/spec/unit/config_spec.rb +0 -30
- data/spec/unit/configuration/new_spec.rb +0 -28
- data/spec/unit/conversions/fetch_spec.rb +0 -16
- data/spec/unit/conversions/register_spec.rb +0 -58
- data/spec/unit/conversions/to_hash_spec.rb +0 -37
- data/spec/unit/convert_spec.rb +0 -130
- data/spec/unit/converters/array/array_to_boolean_spec.rb +0 -20
- data/spec/unit/converters/array/array_to_numeric_spec.rb +0 -20
- data/spec/unit/converters/array/array_to_set_spec.rb +0 -16
- data/spec/unit/converters/array/object_to_array_spec.rb +0 -19
- data/spec/unit/converters/array/string_to_array_spec.rb +0 -31
- data/spec/unit/converters/boolean/boolean_to_integer_spec.rb +0 -24
- data/spec/unit/converters/boolean/integer_to_boolean_spec.rb +0 -20
- data/spec/unit/converters/boolean/string_to_boolean_spec.rb +0 -34
- data/spec/unit/converters/date_time/string_to_date_spec.rb +0 -24
- data/spec/unit/converters/date_time/string_to_datetime_spec.rb +0 -30
- data/spec/unit/converters/date_time/string_to_time_spec.rb +0 -28
- data/spec/unit/converters/numeric/string_to_float_spec.rb +0 -46
- data/spec/unit/converters/numeric/string_to_integer_spec.rb +0 -60
- data/spec/unit/converters/numeric/string_to_numeric_spec.rb +0 -30
- data/spec/unit/converters/range/string_to_range_spec.rb +0 -33
- data/spec/unit/inspect_spec.rb +0 -14
- data/spec/unit/new_spec.rb +0 -10
- data/spec/unit/register_spec.rb +0 -15
- data/tasks/console.rake +0 -11
- data/tasks/coverage.rake +0 -11
- data/tasks/spec.rake +0 -29
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 68eb8e7721b9b177485217e74aecb8e9c9bbe2995615bdb21d2601c04afe2bb2
|
4
|
+
data.tar.gz: d80270564204a03b60dacfc21c0e4da9283a0c387bef4fe1566829e9bce9bd54
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5638c5411b0f5a2f4b2fe59d78ef59c59a4c0de675989c8c3fe40b6694f02b11ecb87f8294e1cc9147e17efcc6c7b906f9cbb23caa75e4b21c32e48607b01a08
|
7
|
+
data.tar.gz: b89a52e45e1aab9d36121a7ef17aba54436bdb3fa58182df77808d57cb146e0688cb05e335b6464b6d66bf396bf579fbe61ea0ecb9abdac59ed9d80cbf992f26
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,10 @@
|
|
1
1
|
# Change log
|
2
2
|
|
3
|
+
## [v0.6.0] - 2020-03-08
|
4
|
+
|
5
|
+
### Changed
|
6
|
+
* Change gemspec to remove test artifacts
|
7
|
+
|
3
8
|
## [v0.5.1] - 2019-11-24
|
4
9
|
|
5
10
|
### Changed
|
@@ -52,6 +57,7 @@
|
|
52
57
|
|
53
58
|
* Initial implementation and release
|
54
59
|
|
60
|
+
[v0.6.0]: https://github.com/piotrmurach/necromancer/compare/v0.5.1...v0.6.0
|
55
61
|
[v0.5.1]: https://github.com/piotrmurach/necromancer/compare/v0.5.0...v0.5.1
|
56
62
|
[v0.5.0]: https://github.com/piotrmurach/necromancer/compare/v0.4.0...v0.5.0
|
57
63
|
[v0.4.0]: https://github.com/piotrmurach/necromancer/compare/v0.3.0...v0.4.0
|
data/lib/necromancer.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative
|
4
|
-
require_relative
|
3
|
+
require_relative "necromancer/context"
|
4
|
+
require_relative "necromancer/version"
|
5
5
|
|
6
6
|
module Necromancer
|
7
7
|
# Raised when cannot conver to a given type
|
@@ -26,7 +26,8 @@ module Necromancer
|
|
26
26
|
# Convenience to directly call conversion
|
27
27
|
#
|
28
28
|
# @example
|
29
|
-
# Necromancer.convert(
|
29
|
+
# Necromancer.convert("1").to(:integer)
|
30
|
+
# # => 1
|
30
31
|
#
|
31
32
|
# @return [ConversionTarget]
|
32
33
|
#
|
data/lib/necromancer/context.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "forwardable"
|
4
4
|
|
5
|
-
require_relative
|
6
|
-
require_relative
|
7
|
-
require_relative
|
5
|
+
require_relative "configuration"
|
6
|
+
require_relative "conversions"
|
7
|
+
require_relative "conversion_target"
|
8
8
|
|
9
9
|
module Necromancer
|
10
10
|
# A class used by Necromancer to provide user interace
|
@@ -20,12 +20,12 @@ module Necromancer
|
|
20
20
|
if UndefinedValue.equal?(value)
|
21
21
|
unless block
|
22
22
|
raise ArgumentError,
|
23
|
-
|
23
|
+
"You need to pass either argument or a block to `convert`."
|
24
24
|
end
|
25
25
|
new(context, block.call)
|
26
26
|
elsif block
|
27
27
|
raise ArgumentError,
|
28
|
-
|
28
|
+
"You cannot pass both an argument and a block to `convert`."
|
29
29
|
else
|
30
30
|
new(context, value)
|
31
31
|
end
|
@@ -34,7 +34,7 @@ module Necromancer
|
|
34
34
|
# Allows to specify conversion source type
|
35
35
|
#
|
36
36
|
# @example
|
37
|
-
# converter.convert(
|
37
|
+
# converter.convert("1").from(:string).to(:numeric) # => 1
|
38
38
|
#
|
39
39
|
# @return [ConversionType]
|
40
40
|
#
|
@@ -47,10 +47,10 @@ module Necromancer
|
|
47
47
|
# Runs a given conversion
|
48
48
|
#
|
49
49
|
# @example
|
50
|
-
# converter.convert(
|
50
|
+
# converter.convert("1").to(:numeric) # => 1
|
51
51
|
#
|
52
52
|
# @example
|
53
|
-
# converter.convert(
|
53
|
+
# converter.convert("1") >> Integer # => 1
|
54
54
|
#
|
55
55
|
# @return [Object]
|
56
56
|
# the converted target type
|
@@ -1,12 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative
|
4
|
-
require_relative
|
5
|
-
require_relative
|
6
|
-
require_relative
|
7
|
-
require_relative
|
8
|
-
require_relative
|
9
|
-
require_relative
|
3
|
+
require_relative "configuration"
|
4
|
+
require_relative "converter"
|
5
|
+
require_relative "converters/array"
|
6
|
+
require_relative "converters/boolean"
|
7
|
+
require_relative "converters/date_time"
|
8
|
+
require_relative "converters/numeric"
|
9
|
+
require_relative "converters/range"
|
10
10
|
|
11
11
|
module Necromancer
|
12
12
|
# Represents the context used to configure various converters
|
@@ -14,7 +14,7 @@ module Necromancer
|
|
14
14
|
#
|
15
15
|
# @api public
|
16
16
|
class Conversions
|
17
|
-
DELIMITER =
|
17
|
+
DELIMITER = "->"
|
18
18
|
|
19
19
|
# Creates a new conversions map
|
20
20
|
#
|
@@ -101,8 +101,8 @@ module Necromancer
|
|
101
101
|
# @api private
|
102
102
|
def generate_key(converter)
|
103
103
|
parts = []
|
104
|
-
parts << (converter.source ? converter.source.to_s :
|
105
|
-
parts << (converter.target ? converter.target.to_s :
|
104
|
+
parts << (converter.source ? converter.source.to_s : "none")
|
105
|
+
parts << (converter.target ? converter.target.to_s : "none")
|
106
106
|
parts.join(DELIMITER)
|
107
107
|
end
|
108
108
|
|
@@ -1,8 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "set"
|
4
4
|
|
5
|
-
require_relative
|
5
|
+
require_relative "../converter"
|
6
6
|
|
7
7
|
module Necromancer
|
8
8
|
# Container for Array converter classes
|
@@ -12,10 +12,10 @@ module Necromancer
|
|
12
12
|
# Convert string value to array
|
13
13
|
#
|
14
14
|
# @example
|
15
|
-
# converter.call(
|
15
|
+
# converter.call("a, b, c") # => ["a", "b", "c"]
|
16
16
|
#
|
17
17
|
# @example
|
18
|
-
# converter.call(
|
18
|
+
# converter.call("1 - 2 - 3") # => [1, 2, 3]
|
19
19
|
#
|
20
20
|
# @api public
|
21
21
|
def call(value, options = {})
|
@@ -36,7 +36,7 @@ module Necromancer
|
|
36
36
|
# Convert an array to an array of numeric values
|
37
37
|
#
|
38
38
|
# @example
|
39
|
-
# converter.call([
|
39
|
+
# converter.call(["1", "2.3", "3.0]) # => [1, 2.3, 3.0]
|
40
40
|
#
|
41
41
|
# @param [Array] value
|
42
42
|
# the value to convert
|
@@ -53,7 +53,7 @@ module Necromancer
|
|
53
53
|
# An object that converts an array to an array with boolean values
|
54
54
|
class ArrayToBooleanConverter < Converter
|
55
55
|
# @example
|
56
|
-
# converter.call([
|
56
|
+
# converter.call(["t", "f", "yes", "no"]) # => [true, false, true, false]
|
57
57
|
#
|
58
58
|
# @param [Array] value
|
59
59
|
# the array value to boolean
|
@@ -1,10 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require "date"
|
4
|
+
require "time"
|
5
5
|
|
6
|
-
require_relative
|
7
|
-
require_relative
|
6
|
+
require_relative "../converter"
|
7
|
+
require_relative "../null_converter"
|
8
8
|
|
9
9
|
module Necromancer
|
10
10
|
# Container for Date converter classes
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative
|
4
|
-
require_relative
|
3
|
+
require_relative "../converter"
|
4
|
+
require_relative "../null_converter"
|
5
5
|
|
6
6
|
module Necromancer
|
7
7
|
# Container for Numeric converter classes
|
@@ -15,7 +15,7 @@ module Necromancer
|
|
15
15
|
# Convert string value to integer
|
16
16
|
#
|
17
17
|
# @example
|
18
|
-
# converter.call(
|
18
|
+
# converter.call("1abc") # => 1
|
19
19
|
#
|
20
20
|
# @api public
|
21
21
|
def call(value, **options)
|
@@ -31,7 +31,7 @@ module Necromancer
|
|
31
31
|
# Convert integer value to string
|
32
32
|
#
|
33
33
|
# @example
|
34
|
-
# converter.call(1) # =>
|
34
|
+
# converter.call(1) # => "1"
|
35
35
|
#
|
36
36
|
# @api public
|
37
37
|
def call(value, **_)
|
@@ -44,7 +44,7 @@ module Necromancer
|
|
44
44
|
# Convert string to float value
|
45
45
|
#
|
46
46
|
# @example
|
47
|
-
# converter.call(
|
47
|
+
# converter.call("1.2") # => 1.2
|
48
48
|
#
|
49
49
|
# @api public
|
50
50
|
def call(value, **options)
|
@@ -60,10 +60,10 @@ module Necromancer
|
|
60
60
|
# Convert string to numeric value
|
61
61
|
#
|
62
62
|
# @example
|
63
|
-
# converter.call(
|
63
|
+
# converter.call("1.0") # => 1.0
|
64
64
|
#
|
65
65
|
# @example
|
66
|
-
# converter.call(
|
66
|
+
# converter.call("1") # => 1
|
67
67
|
#
|
68
68
|
# @api public
|
69
69
|
def call(value, **options)
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative
|
4
|
-
require_relative
|
3
|
+
require_relative "../converter"
|
4
|
+
require_relative "../null_converter"
|
5
5
|
|
6
6
|
module Necromancer
|
7
7
|
# Container for Range converter classes
|
@@ -19,10 +19,10 @@ module Necromancer
|
|
19
19
|
# @param [Object] value
|
20
20
|
#
|
21
21
|
# @example
|
22
|
-
# converter.call(
|
22
|
+
# converter.call("0,9") # => (0..9)
|
23
23
|
#
|
24
24
|
# @example
|
25
|
-
# converter.call(
|
25
|
+
# converter.call("0-9") # => (0..9)
|
26
26
|
#
|
27
27
|
# @api public
|
28
28
|
def call(value, options = {})
|
@@ -31,9 +31,9 @@ module Necromancer
|
|
31
31
|
when SINGLE_DIGIT_MATCHER
|
32
32
|
::Range.new($1.to_i, $1.to_i)
|
33
33
|
when DIGIT_MATCHER
|
34
|
-
::Range.new($1.to_i, $3.to_i, $2 ==
|
34
|
+
::Range.new($1.to_i, $3.to_i, $2 == "...")
|
35
35
|
when LETTER_MATCHER
|
36
|
-
::Range.new($1.to_s, $3.to_s, $2 ==
|
36
|
+
::Range.new($1.to_s, $3.to_s, $2 == "...")
|
37
37
|
else
|
38
38
|
strict ? raise_conversion_type(value) : value
|
39
39
|
end
|
data/lib/necromancer/version.rb
CHANGED
metadata
CHANGED
@@ -1,29 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: necromancer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Piotr Murach
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-03-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: bundler
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - ">="
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '1.6'
|
20
|
-
type: :development
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - ">="
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '1.6'
|
27
13
|
- !ruby/object:Gem::Dependency
|
28
14
|
name: rake
|
29
15
|
requirement: !ruby/object:Gem::Requirement
|
@@ -54,15 +40,17 @@ dependencies:
|
|
54
40
|
version: '3.0'
|
55
41
|
description: Conversion from one object type to another with a bit of black magic.
|
56
42
|
email:
|
57
|
-
-
|
43
|
+
- piotr@piotrmurach.com
|
58
44
|
executables: []
|
59
45
|
extensions: []
|
60
|
-
extra_rdoc_files:
|
46
|
+
extra_rdoc_files:
|
47
|
+
- README.md
|
48
|
+
- CHANGELOG.md
|
49
|
+
- LICENSE.txt
|
61
50
|
files:
|
62
51
|
- CHANGELOG.md
|
63
52
|
- LICENSE.txt
|
64
53
|
- README.md
|
65
|
-
- Rakefile
|
66
54
|
- lib/necromancer.rb
|
67
55
|
- lib/necromancer/configuration.rb
|
68
56
|
- lib/necromancer/context.rb
|
@@ -76,36 +64,6 @@ files:
|
|
76
64
|
- lib/necromancer/converters/range.rb
|
77
65
|
- lib/necromancer/null_converter.rb
|
78
66
|
- lib/necromancer/version.rb
|
79
|
-
- necromancer.gemspec
|
80
|
-
- spec/spec_helper.rb
|
81
|
-
- spec/unit/can_spec.rb
|
82
|
-
- spec/unit/config_spec.rb
|
83
|
-
- spec/unit/configuration/new_spec.rb
|
84
|
-
- spec/unit/conversions/fetch_spec.rb
|
85
|
-
- spec/unit/conversions/register_spec.rb
|
86
|
-
- spec/unit/conversions/to_hash_spec.rb
|
87
|
-
- spec/unit/convert_spec.rb
|
88
|
-
- spec/unit/converters/array/array_to_boolean_spec.rb
|
89
|
-
- spec/unit/converters/array/array_to_numeric_spec.rb
|
90
|
-
- spec/unit/converters/array/array_to_set_spec.rb
|
91
|
-
- spec/unit/converters/array/object_to_array_spec.rb
|
92
|
-
- spec/unit/converters/array/string_to_array_spec.rb
|
93
|
-
- spec/unit/converters/boolean/boolean_to_integer_spec.rb
|
94
|
-
- spec/unit/converters/boolean/integer_to_boolean_spec.rb
|
95
|
-
- spec/unit/converters/boolean/string_to_boolean_spec.rb
|
96
|
-
- spec/unit/converters/date_time/string_to_date_spec.rb
|
97
|
-
- spec/unit/converters/date_time/string_to_datetime_spec.rb
|
98
|
-
- spec/unit/converters/date_time/string_to_time_spec.rb
|
99
|
-
- spec/unit/converters/numeric/string_to_float_spec.rb
|
100
|
-
- spec/unit/converters/numeric/string_to_integer_spec.rb
|
101
|
-
- spec/unit/converters/numeric/string_to_numeric_spec.rb
|
102
|
-
- spec/unit/converters/range/string_to_range_spec.rb
|
103
|
-
- spec/unit/inspect_spec.rb
|
104
|
-
- spec/unit/new_spec.rb
|
105
|
-
- spec/unit/register_spec.rb
|
106
|
-
- tasks/console.rake
|
107
|
-
- tasks/coverage.rake
|
108
|
-
- tasks/spec.rake
|
109
67
|
homepage: https://github.com/piotrmurach/necromancer
|
110
68
|
licenses:
|
111
69
|
- MIT
|
@@ -130,34 +88,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
130
88
|
- !ruby/object:Gem::Version
|
131
89
|
version: '0'
|
132
90
|
requirements: []
|
133
|
-
rubygems_version: 3.
|
91
|
+
rubygems_version: 3.1.2
|
134
92
|
signing_key:
|
135
93
|
specification_version: 4
|
136
94
|
summary: Conversion from one object type to another with a bit of black magic.
|
137
|
-
test_files:
|
138
|
-
- spec/spec_helper.rb
|
139
|
-
- spec/unit/can_spec.rb
|
140
|
-
- spec/unit/config_spec.rb
|
141
|
-
- spec/unit/configuration/new_spec.rb
|
142
|
-
- spec/unit/conversions/fetch_spec.rb
|
143
|
-
- spec/unit/conversions/register_spec.rb
|
144
|
-
- spec/unit/conversions/to_hash_spec.rb
|
145
|
-
- spec/unit/convert_spec.rb
|
146
|
-
- spec/unit/converters/array/array_to_boolean_spec.rb
|
147
|
-
- spec/unit/converters/array/array_to_numeric_spec.rb
|
148
|
-
- spec/unit/converters/array/array_to_set_spec.rb
|
149
|
-
- spec/unit/converters/array/object_to_array_spec.rb
|
150
|
-
- spec/unit/converters/array/string_to_array_spec.rb
|
151
|
-
- spec/unit/converters/boolean/boolean_to_integer_spec.rb
|
152
|
-
- spec/unit/converters/boolean/integer_to_boolean_spec.rb
|
153
|
-
- spec/unit/converters/boolean/string_to_boolean_spec.rb
|
154
|
-
- spec/unit/converters/date_time/string_to_date_spec.rb
|
155
|
-
- spec/unit/converters/date_time/string_to_datetime_spec.rb
|
156
|
-
- spec/unit/converters/date_time/string_to_time_spec.rb
|
157
|
-
- spec/unit/converters/numeric/string_to_float_spec.rb
|
158
|
-
- spec/unit/converters/numeric/string_to_integer_spec.rb
|
159
|
-
- spec/unit/converters/numeric/string_to_numeric_spec.rb
|
160
|
-
- spec/unit/converters/range/string_to_range_spec.rb
|
161
|
-
- spec/unit/inspect_spec.rb
|
162
|
-
- spec/unit/new_spec.rb
|
163
|
-
- spec/unit/register_spec.rb
|
95
|
+
test_files: []
|