ruby-dagger 0.2.1 → 0.3.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 +37 -0
- data/lib/dagger/generate/float.rb +22 -0
- data/lib/dagger/generate/integer.rb +24 -0
- data/lib/dagger/{generator → generate}/regexp.rb +1 -1
- data/lib/dagger/{generator → generate}/require.rb +1 -1
- data/lib/dagger/{generator → generate}/require_name.rb +1 -1
- data/lib/dagger/{generator → generate}/string.rb +1 -1
- data/lib/dagger/generator.rb +5 -5
- data/lib/dagger/numeric_generator.rb +84 -0
- metadata +10 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0e0b2aac30db4d1b00f0c2142f9f67f3cbc7bf2c48c21c6769f488428e605f1e
|
4
|
+
data.tar.gz: 6a03b80f550cc179fff40d582ba960011f57dda457fc728e130678e0697a00eb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 363469d20a35b20b81087b5c197f99a9175e02a2ea6b4ebae9d4f2fc3ce348710cd1f1e15bc5ff4c07579d5f6b3e8e5aa98ea5a2a8c7c38c2924decb8af55314
|
7
|
+
data.tar.gz: 7745518212caef8a211a8d2750f177a1cfd092a4bf5161fa75826180ae478da90816e5c0afc748f2ad6a5294887e557a966551784e9cf393a1abeebae5f968ec
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# Changelog
|
2
|
+
All notable changes to this project will be documented in this file.
|
3
|
+
|
4
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
5
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
6
|
+
|
7
|
+
## [Unreleased]
|
8
|
+
|
9
|
+
## [0.3.0] - 2019-07-05
|
10
|
+
|
11
|
+
### Added
|
12
|
+
- Numeric default values
|
13
|
+
- integer: for rounded integer values
|
14
|
+
- float: for floating point values
|
15
|
+
- both types also support summarizing functions
|
16
|
+
- sum: arithmetic sum of the values
|
17
|
+
- product: arithmetic product of the values
|
18
|
+
- arithmetic_mean: the [arithmetic mean] of the values
|
19
|
+
- geometric_mean: the [geometric mean] of the values
|
20
|
+
- harmonic_mean: the [harmonic mean] of the values
|
21
|
+
|
22
|
+
[arithmethic mean]: https://en.wikipedia.org/wiki/Mean#Arithmetic_mean_(AM)
|
23
|
+
[geometric mean]: https://en.wikipedia.org/wiki/Mean#Geometric_mean_(GM)
|
24
|
+
[harmonic mean]: https://en.wikipedia.org/wiki/Mean#Harmonic_mean_(HM)
|
25
|
+
|
26
|
+
### Changed
|
27
|
+
- Default value arguments used to be wrapped in arrays based on responding
|
28
|
+
to `#enum`, but are now based on `#to_ary`, to ensure that hashes are also
|
29
|
+
wrapped.
|
30
|
+
|
31
|
+
## [Older]
|
32
|
+
These releases have no change logs.
|
33
|
+
|
34
|
+
|
35
|
+
[Unreleased]: https://github.com/notCalle/ruby-dagger/compare/v0.3.0..HEAD
|
36
|
+
[0.3.0]: https://github.com/notCalle/ruby-dagger/compare/v0.2.1..v0.3.0
|
37
|
+
[Older]: https://github.com/notCalle/ruby-dagger/releases/tag/v0.2.1
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../numeric_generator'
|
4
|
+
|
5
|
+
module Dagger
|
6
|
+
module Generate
|
7
|
+
# Generate a floating point value from a format string
|
8
|
+
#
|
9
|
+
# _default.key:
|
10
|
+
# - float: "#{key}"
|
11
|
+
# - float:
|
12
|
+
# - "#{key}"
|
13
|
+
# - ...
|
14
|
+
class Float < NumericGenerator
|
15
|
+
private
|
16
|
+
|
17
|
+
def from_s(string)
|
18
|
+
string.to_f
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../numeric_generator'
|
4
|
+
|
5
|
+
module Dagger
|
6
|
+
module Generate
|
7
|
+
# Generate an integer value from a format string
|
8
|
+
#
|
9
|
+
# _default.key:
|
10
|
+
# - integer: "#{key}"
|
11
|
+
# - integer:
|
12
|
+
# - "#{key}"
|
13
|
+
# - ...
|
14
|
+
# - integer:
|
15
|
+
# accumulate:
|
16
|
+
class Integer < NumericGenerator
|
17
|
+
private
|
18
|
+
|
19
|
+
def from_s(string)
|
20
|
+
string.to_f.round
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -35,7 +35,7 @@ module Dagger
|
|
35
35
|
def match_regexps(key, regexps)
|
36
36
|
string = dictionary[key]
|
37
37
|
|
38
|
-
|
38
|
+
array(regexps).each_with_object({}) do |regexp, matches|
|
39
39
|
matchdata = ::Regexp.new(regexp).match(string)
|
40
40
|
next if matchdata.nil?
|
41
41
|
|
data/lib/dagger/generator.rb
CHANGED
@@ -60,12 +60,12 @@ module Dagger
|
|
60
60
|
kwargs.each { |key, value| @context[key] = value }
|
61
61
|
end
|
62
62
|
|
63
|
-
# Make an array of a value unless it is already
|
63
|
+
# Make an array of a value unless it is already an array
|
64
64
|
#
|
65
65
|
# :call-seq:
|
66
|
-
#
|
67
|
-
def
|
68
|
-
value.respond_to?(:
|
66
|
+
# array(value) => value || [value]
|
67
|
+
def array(value)
|
68
|
+
value.respond_to?(:to_ary) ? value : [value]
|
69
69
|
end
|
70
70
|
|
71
71
|
# Format a +string+ with values from a +dictionary+
|
@@ -85,4 +85,4 @@ module Dagger
|
|
85
85
|
end
|
86
86
|
end
|
87
87
|
|
88
|
-
Dir[__dir__ + '/
|
88
|
+
Dir[__dir__ + '/generate/*.rb'].each { |file| load(file) }
|
@@ -0,0 +1,84 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'generator'
|
4
|
+
|
5
|
+
module Dagger
|
6
|
+
module Generate
|
7
|
+
# Abstract base for generating numeric values
|
8
|
+
class NumericGenerator < Dagger::Generator
|
9
|
+
def process(args)
|
10
|
+
array(args).each do |arg|
|
11
|
+
result = process_recurse(arg)
|
12
|
+
yield result unless result.nil?
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def process_recurse(arg)
|
19
|
+
case arg
|
20
|
+
when Hash
|
21
|
+
process_hash(arg)
|
22
|
+
when ::String
|
23
|
+
str = format_string(arg)
|
24
|
+
from_s(str) unless str.nil?
|
25
|
+
else
|
26
|
+
from_s(arg)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def process_hash(hash)
|
31
|
+
print(hash)
|
32
|
+
hash.each do |key, args|
|
33
|
+
result = process_hash_item(key, args)
|
34
|
+
return result unless result.nil?
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def process_hash_item(key, args)
|
39
|
+
case args
|
40
|
+
when ::String
|
41
|
+
send("numeric_#{key}", dictionary[args])
|
42
|
+
else
|
43
|
+
send("numeric_#{key}", process_args(args))
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def process_args(args)
|
48
|
+
args = array(args).flat_map { |arg| process_recurse(arg) }
|
49
|
+
args.delete(nil)
|
50
|
+
args
|
51
|
+
end
|
52
|
+
|
53
|
+
def numeric_values(args)
|
54
|
+
args.map { |value| from_s(value) }
|
55
|
+
end
|
56
|
+
|
57
|
+
def numeric_sum(args)
|
58
|
+
args.sum
|
59
|
+
end
|
60
|
+
|
61
|
+
def numeric_product(args)
|
62
|
+
args.reduce(:*)
|
63
|
+
end
|
64
|
+
|
65
|
+
def numeric_arithmetic_mean(args)
|
66
|
+
return if args.empty?
|
67
|
+
|
68
|
+
numeric_sum(args) / args.length
|
69
|
+
end
|
70
|
+
|
71
|
+
def numeric_geometric_mean(args)
|
72
|
+
return if args.empty?
|
73
|
+
|
74
|
+
numeric_product(args)**(1.0 / args.length)
|
75
|
+
end
|
76
|
+
|
77
|
+
def numeric_harmonic_mean(args)
|
78
|
+
return if args.empty?
|
79
|
+
|
80
|
+
args.length / args.map { |n| 1.0 / n }.sum
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-dagger
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Calle Englund
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-07-
|
11
|
+
date: 2019-07-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: key_tree
|
@@ -175,6 +175,7 @@ files:
|
|
175
175
|
- ".rspec"
|
176
176
|
- ".rubocop.yml"
|
177
177
|
- ".travis.yml"
|
178
|
+
- CHANGELOG.md
|
178
179
|
- CODE_OF_CONDUCT.md
|
179
180
|
- Gemfile
|
180
181
|
- LICENSE.txt
|
@@ -186,12 +187,15 @@ files:
|
|
186
187
|
- lib/dagger.rb
|
187
188
|
- lib/dagger/context.rb
|
188
189
|
- lib/dagger/default.rb
|
190
|
+
- lib/dagger/generate/float.rb
|
191
|
+
- lib/dagger/generate/integer.rb
|
192
|
+
- lib/dagger/generate/regexp.rb
|
193
|
+
- lib/dagger/generate/require.rb
|
194
|
+
- lib/dagger/generate/require_name.rb
|
195
|
+
- lib/dagger/generate/string.rb
|
189
196
|
- lib/dagger/generator.rb
|
190
|
-
- lib/dagger/generator/regexp.rb
|
191
|
-
- lib/dagger/generator/require.rb
|
192
|
-
- lib/dagger/generator/require_name.rb
|
193
|
-
- lib/dagger/generator/string.rb
|
194
197
|
- lib/dagger/graph.rb
|
198
|
+
- lib/dagger/numeric_generator.rb
|
195
199
|
- lib/dagger/version.rb
|
196
200
|
- lib/dagger/vertex.rb
|
197
201
|
- ruby-dagger.gemspec
|