parameter_substitution 1.1.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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 28e66926e2dc18a7902f3670410a6290b34d44da4f490045d15787085eacf800
|
4
|
+
data.tar.gz: b3618e294a0c4f07573382bacc574f8684abebf1dd8da4e1eb5752027c9e2470
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2b383ce1da83355a4c5db67561491cfc83636bb4b7ab97d1fe72e1ecc622b44451c8ff1be54083be0b69648a16e925eb1253552b35feadacdfb13a91e86afe67
|
7
|
+
data.tar.gz: 3fb0bd0c28df9e4b6b8b4155894717aa31e1d5f0773b5060769956b55c58ceec835537cd9574506e568191375673205823b9edf7bc7be57ae64b6f2f9c75e65f
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class ParameterSubstitution::Formatters::IfTruthy < ParameterSubstitution::Formatters::Base
|
4
|
+
TRUTHY_VALUES = [true, "true", "t", 1, "1", "on", "yes"].freeze
|
5
|
+
|
6
|
+
def self.description
|
7
|
+
"If the input is truthy (i.e. #{TRUTHY_VALUES.inspect}) then the input is replaced with the first argument. Otherwise, the input is replaced with the second argument."
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.has_parameters?
|
11
|
+
true
|
12
|
+
end
|
13
|
+
|
14
|
+
def initialize(value_if_true, value_if_false)
|
15
|
+
@value_if_true = value_if_true
|
16
|
+
@value_if_false = value_if_false
|
17
|
+
end
|
18
|
+
|
19
|
+
def format(value)
|
20
|
+
if TRUTHY_VALUES.include?(downcase_if_string(value))
|
21
|
+
@value_if_true
|
22
|
+
else
|
23
|
+
@value_if_false
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
:private
|
28
|
+
|
29
|
+
def downcase_if_string(value)
|
30
|
+
if value.is_a?(String)
|
31
|
+
value.downcase
|
32
|
+
else
|
33
|
+
value
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: parameter_substitution
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Invoca Development
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-05-
|
11
|
+
date: 2020-05-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -111,6 +111,7 @@ files:
|
|
111
111
|
- lib/parameter_substitution/formatters/duration_grouped_by_description.rb
|
112
112
|
- lib/parameter_substitution/formatters/greater_than_value.rb
|
113
113
|
- lib/parameter_substitution/formatters/if_nil.rb
|
114
|
+
- lib/parameter_substitution/formatters/if_truthy.rb
|
114
115
|
- lib/parameter_substitution/formatters/in_timezone.rb
|
115
116
|
- lib/parameter_substitution/formatters/json_parse.rb
|
116
117
|
- lib/parameter_substitution/formatters/left.rb
|