cmdlet 0.0.7 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.builders/.templates/cmdlet.rb +26 -0
- data/.builders/.templates/{command_spec.rb → cmdlet_spec.rb} +4 -4
- data/.builders/.templates/require_all_cmdlets.rb +5 -0
- data/.builders/_.rb +7 -1
- data/.builders/boot.rb +2 -0
- data/.builders/data/categories.json +2 -10
- data/.builders/data/cmdlets/array.json +121 -0
- data/.builders/data/cmdlets/case.json +313 -0
- data/.builders/data/cmdlets/comparison.json +245 -0
- data/.builders/data/cmdlets/inflection.json +129 -0
- data/.builders/director/category_builder.rb +26 -0
- data/.builders/director/category_dao.rb +38 -0
- data/.builders/director/category_director.rb +24 -10
- data/.builders/director/cmdlet_builder.rb +27 -34
- data/.builders/director/cmdlet_child.rb +16 -44
- data/.builders/director/cmdlet_dao.rb +29 -0
- data/.builders/director/cmdlet_director.rb +37 -13
- data/.builders/director/dao.rb +16 -0
- data/.builders/documents/commands.rb +15 -16
- data/.builders/documents/use_cases.rb +32 -34
- data/.builders/documents/x_functions.rb +7 -10
- data/.builders/generators/01-bootstrap.rb +112 -112
- data/.builders/generators/20-categories.rb +16 -0
- data/.builders/generators/30-commands-bak.rb +53 -0
- data/.builders/generators/cmdlets/array.rb +71 -0
- data/.builders/generators/cmdlets/case.rb +184 -0
- data/.builders/generators/cmdlets/comparison.rb +126 -0
- data/.builders/generators/cmdlets/inflection.rb +93 -0
- data/CHANGELOG.md +37 -0
- data/Guardfile +1 -1
- data/lib/cmdlet/_.rb +33 -0
- data/lib/cmdlet/array/join.rb +8 -10
- data/lib/cmdlet/array/join_post.rb +22 -0
- data/lib/cmdlet/array/join_pre.rb +22 -0
- data/lib/cmdlet/base_cmdlet.rb +17 -0
- data/lib/cmdlet/case/back_slash.rb +16 -0
- data/lib/cmdlet/case/camel.rb +16 -0
- data/lib/cmdlet/case/constant.rb +16 -0
- data/lib/cmdlet/case/dash.rb +16 -0
- data/lib/cmdlet/case/dot.rb +16 -0
- data/lib/cmdlet/case/double_colon.rb +16 -0
- data/lib/cmdlet/case/human.rb +20 -0
- data/lib/cmdlet/case/lamel.rb +16 -0
- data/lib/cmdlet/case/lower.rb +18 -0
- data/lib/cmdlet/case/sentence.rb +20 -0
- data/lib/cmdlet/case/slash.rb +16 -0
- data/lib/cmdlet/case/snake.rb +16 -0
- data/lib/cmdlet/case/title.rb +21 -0
- data/lib/cmdlet/case/upper.rb +18 -0
- data/lib/cmdlet/comparison/and.rb +16 -0
- data/lib/cmdlet/comparison/default.rb +20 -0
- data/lib/cmdlet/comparison/eq.rb +20 -0
- data/lib/cmdlet/comparison/gt.rb +17 -0
- data/lib/cmdlet/comparison/gte.rb +17 -0
- data/lib/cmdlet/comparison/lt.rb +17 -0
- data/lib/cmdlet/comparison/lte.rb +17 -0
- data/lib/cmdlet/comparison/ne.rb +20 -0
- data/lib/cmdlet/comparison/or.rb +16 -0
- data/lib/cmdlet/inflection/ordinal.rb +20 -0
- data/lib/cmdlet/inflection/ordinalize.rb +20 -0
- data/lib/cmdlet/inflection/pluralize.rb +20 -0
- data/lib/cmdlet/inflection/pluralize_by_number.rb +28 -0
- data/lib/cmdlet/inflection/singularize.rb +20 -0
- data/lib/cmdlet/version.rb +1 -1
- data/lib/cmdlet.rb +5 -0
- data/package-lock.json +2 -2
- data/package.json +1 -1
- metadata +51 -9
- data/.builders/.templates/all_commands.rb +0 -5
- data/.builders/.templates/command.rb +0 -26
- data/.builders/documents/categories.rb +0 -24
- data/.builders/documents/cmdlets.rb +0 -30
- data/.builders/generators/20-commands.rb +0 -54
- data/.builders/generators/25-categories.rb +0 -20
@@ -0,0 +1,53 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
KManager.action :commands_bak do
|
4
|
+
action do
|
5
|
+
puts commands.first.function_description
|
6
|
+
# Ruby Gem Bootstrap
|
7
|
+
director = KDirector::Dsls::BasicDsl
|
8
|
+
.init(k_builder,
|
9
|
+
template_base_folder: '',
|
10
|
+
on_exist: :skip, # %i[skip write compare]
|
11
|
+
on_action: :queue # %i[queue execute]
|
12
|
+
)
|
13
|
+
.blueprint(
|
14
|
+
active: true,
|
15
|
+
name: :build_commands,
|
16
|
+
description: 'Build Commandlets',
|
17
|
+
on_exist: :write
|
18
|
+
) do
|
19
|
+
cd(:lib)
|
20
|
+
|
21
|
+
# builder
|
22
|
+
# .add_file('FUNCTIONS.md',
|
23
|
+
# template_file: 'FUNCTIONS.md',
|
24
|
+
# categories: categories.sort_by { |r| r.name },
|
25
|
+
# functions: functions.sort_by { |r| [r.category, r.name] },
|
26
|
+
# on_exist: :write)
|
27
|
+
|
28
|
+
add('all_commands.rb',
|
29
|
+
template_file: 'all_commands.rb',
|
30
|
+
commands: commands.sort_by { |r| [r.category, r.name] },
|
31
|
+
on_exist: :write)
|
32
|
+
|
33
|
+
cmdlets.each do |cmdlet|
|
34
|
+
add("#{cmdlet.category}/#{cmdlet.name}.rb",
|
35
|
+
cmdlet: cmdlet,
|
36
|
+
template_file: 'command.rb',
|
37
|
+
on_exist: :write)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
director.play_actions
|
42
|
+
# director.builder.logit
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
KManager.opts.app_name = 'commands'
|
47
|
+
KManager.opts.sleep = 2
|
48
|
+
KManager.opts.reboot_on_kill = 0
|
49
|
+
KManager.opts.reboot_sleep = 4
|
50
|
+
KManager.opts.exception_style = :short
|
51
|
+
KManager.opts.show.time_taken = true
|
52
|
+
KManager.opts.show.finished = true
|
53
|
+
KManager.opts.show.finished_message = 'FINISHED :)'
|
@@ -0,0 +1,71 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
KManager.action :array_commands do
|
4
|
+
action do
|
5
|
+
CmdletDirector
|
6
|
+
.init(k_builder, category: :array)
|
7
|
+
.cmdlet do
|
8
|
+
name :join
|
9
|
+
description 'join an array of values with separator as a string'
|
10
|
+
result 'new String formed by joining the array elements with seperator'
|
11
|
+
|
12
|
+
parameter :values, 'array of values to join', param_type: 'String|Int'
|
13
|
+
parameter :separator, 'separator between values, defaults to comma', default: "','"
|
14
|
+
|
15
|
+
ruby <<-RUBY
|
16
|
+
return false if values.nil? || values.length == 0
|
17
|
+
values = values.reject(&:blank?)
|
18
|
+
return '' if values.length.zero?
|
19
|
+
|
20
|
+
values.join(separator)
|
21
|
+
RUBY
|
22
|
+
end
|
23
|
+
.cmdlet do
|
24
|
+
name :join_pre
|
25
|
+
description 'join an array of values with separator as a string and using the separator at the beginning of string'
|
26
|
+
|
27
|
+
parameter :values, 'array of values to join', param_type: 'String|Int'
|
28
|
+
parameter :separator, 'separator between values, defaults to comma', default: "','"
|
29
|
+
|
30
|
+
ruby <<-'RUBY'
|
31
|
+
return '' if values.nil? || !values.is_a?(::Array)
|
32
|
+
values = values.reject(&:blank?)
|
33
|
+
return '' if values.length.zero?
|
34
|
+
|
35
|
+
"#{separator}#{values.join(separator)}"
|
36
|
+
RUBY
|
37
|
+
end
|
38
|
+
.cmdlet do
|
39
|
+
name :join_pre
|
40
|
+
description 'join an array of values with separator as a string and using the separator at the beginning of string'
|
41
|
+
|
42
|
+
parameter :values, 'array of values to join', param_type: 'String|Int'
|
43
|
+
parameter :separator, 'separator between values, defaults to comma', default: "','"
|
44
|
+
|
45
|
+
ruby <<-'RUBY'
|
46
|
+
return '' if values.nil? || !values.is_a?(::Array)
|
47
|
+
values = values.reject(&:blank?)
|
48
|
+
return '' if values.length.zero?
|
49
|
+
|
50
|
+
"#{separator}#{values.join(separator)}"
|
51
|
+
RUBY
|
52
|
+
end
|
53
|
+
.cmdlet do
|
54
|
+
name :join_post
|
55
|
+
description 'join an array of values with separator as a string and using the separator at the end of string'
|
56
|
+
|
57
|
+
parameter :values, 'array of values to join', param_type: 'String|Int'
|
58
|
+
parameter :separator, 'separator between values, defaults to comma', default: "','"
|
59
|
+
|
60
|
+
ruby <<-'RUBY'
|
61
|
+
return '' if values.nil? || !values.is_a?(::Array)
|
62
|
+
values = values.reject(&:blank?)
|
63
|
+
return '' if values.length.zero?
|
64
|
+
|
65
|
+
"#{values.join(separator)}#{separator}"
|
66
|
+
RUBY
|
67
|
+
end
|
68
|
+
.generate
|
69
|
+
.debug
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,184 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
KManager.action :case_commands do
|
4
|
+
action do
|
5
|
+
CmdletDirector
|
6
|
+
.init(k_builder, category: :case)
|
7
|
+
.cmdlet do
|
8
|
+
name :back_slash
|
9
|
+
description 'Convert to back slash notation'
|
10
|
+
result 'value converted to back_slash case'
|
11
|
+
|
12
|
+
parameter :value, 'value - to be converted', param_type: 'String|Int'
|
13
|
+
|
14
|
+
ruby <<-'RUBY'
|
15
|
+
tokenizer.parse(value, preserve_case: true, separator: '\\')
|
16
|
+
RUBY
|
17
|
+
end
|
18
|
+
.cmdlet do
|
19
|
+
name :camel
|
20
|
+
description "Camel case the characters in the given 'string'"
|
21
|
+
result 'value converted to camel case'
|
22
|
+
|
23
|
+
parameter :value, 'value - to be converted', param_type: 'String|Int'
|
24
|
+
|
25
|
+
ruby <<-'RUBY'
|
26
|
+
tokenizer.parse(value).underscore.camelize
|
27
|
+
RUBY
|
28
|
+
end
|
29
|
+
.cmdlet do
|
30
|
+
name :constant
|
31
|
+
description "Constant case the characters in the given 'string'"
|
32
|
+
result 'value converted to constant case'
|
33
|
+
|
34
|
+
parameter :value, 'value - to be converted', param_type: 'String|Int'
|
35
|
+
|
36
|
+
ruby <<-'RUBY'
|
37
|
+
tokenizer.parse(value, separator: '_').upcase
|
38
|
+
RUBY
|
39
|
+
end
|
40
|
+
.cmdlet do
|
41
|
+
name :dash
|
42
|
+
description "Dash case the characters in the given 'string'"
|
43
|
+
result 'value converted to dash case'
|
44
|
+
|
45
|
+
parameter :value, 'value - to be converted', param_type: 'String|Int'
|
46
|
+
|
47
|
+
ruby <<-'RUBY'
|
48
|
+
tokenizer.parse(value)
|
49
|
+
RUBY
|
50
|
+
end
|
51
|
+
.cmdlet do
|
52
|
+
name :dot
|
53
|
+
description "Dot case the characters in the given 'string'"
|
54
|
+
result 'value converted to dot case'
|
55
|
+
|
56
|
+
parameter :value, 'value - to be converted', param_type: 'String|Int'
|
57
|
+
|
58
|
+
ruby <<-'RUBY'
|
59
|
+
tokenizer.parse(value, separator: '.')
|
60
|
+
RUBY
|
61
|
+
end
|
62
|
+
.cmdlet do
|
63
|
+
name :double_colon
|
64
|
+
description "Double colon case the characters in the given 'string'"
|
65
|
+
result 'value converted to double_colon case'
|
66
|
+
|
67
|
+
parameter :value, 'value - to be converted', param_type: 'String|Int'
|
68
|
+
|
69
|
+
ruby <<-'RUBY'
|
70
|
+
tokenizer.parse(value, preserve_case: true, separator: '::')
|
71
|
+
RUBY
|
72
|
+
end
|
73
|
+
.cmdlet do
|
74
|
+
name :human
|
75
|
+
description "Human case the characters in the given 'string'"
|
76
|
+
result 'value converted to human case'
|
77
|
+
|
78
|
+
parameter :value, 'value - to be converted', param_type: 'String|Int'
|
79
|
+
|
80
|
+
ruby <<-'RUBY'
|
81
|
+
tokenizer.parse(value,
|
82
|
+
separator: ' ',
|
83
|
+
preserve_case: true,
|
84
|
+
compress_prefix_numerals: false,
|
85
|
+
compress_suffix_numerals: false).humanize
|
86
|
+
RUBY
|
87
|
+
end
|
88
|
+
.cmdlet do
|
89
|
+
name :lamel
|
90
|
+
description "Lower camel case the characters in the given 'string'"
|
91
|
+
result 'value converted to lower camel case'
|
92
|
+
|
93
|
+
parameter :value, 'value - to be converted', param_type: 'String|Int'
|
94
|
+
|
95
|
+
ruby <<-'RUBY'
|
96
|
+
tokenizer.parse(value, separator: '_').camelize(:lower)
|
97
|
+
RUBY
|
98
|
+
end
|
99
|
+
.cmdlet do
|
100
|
+
name :lower
|
101
|
+
description "Lower case the characters in the given 'string'"
|
102
|
+
result 'value converted to lower case'
|
103
|
+
|
104
|
+
parameter :value, 'value - to be converted', param_type: 'String|Int'
|
105
|
+
|
106
|
+
ruby <<-'RUBY'
|
107
|
+
return '' if value.nil?
|
108
|
+
|
109
|
+
value.downcase
|
110
|
+
RUBY
|
111
|
+
end
|
112
|
+
.cmdlet do
|
113
|
+
name :sentence
|
114
|
+
description "Sentence case the characters in the given 'string'"
|
115
|
+
result 'value converted to sentence case'
|
116
|
+
|
117
|
+
parameter :value, 'value - to be converted', param_type: 'String|Int'
|
118
|
+
|
119
|
+
ruby <<-'RUBY'
|
120
|
+
tokenizer.parse(value,
|
121
|
+
separator: ' ',
|
122
|
+
preserve_case: true,
|
123
|
+
compress_prefix_numerals: false,
|
124
|
+
compress_suffix_numerals: false).titleize
|
125
|
+
RUBY
|
126
|
+
end
|
127
|
+
.cmdlet do
|
128
|
+
name :slash
|
129
|
+
description "Slash case the characters in the given 'string'"
|
130
|
+
result 'value converted to slash case'
|
131
|
+
|
132
|
+
parameter :value, 'value - to be converted', param_type: 'String|Int'
|
133
|
+
|
134
|
+
ruby <<-'RUBY'
|
135
|
+
tokenizer.parse(value, preserve_case: true, separator: '/')
|
136
|
+
RUBY
|
137
|
+
end
|
138
|
+
.cmdlet do
|
139
|
+
name :snake
|
140
|
+
description "Snake case the characters in the given 'string'"
|
141
|
+
result 'value converted to snake case'
|
142
|
+
|
143
|
+
parameter :value, 'value - to be converted', param_type: 'String|Int'
|
144
|
+
|
145
|
+
ruby <<-'RUBY'
|
146
|
+
tokenizer.parse(value, separator: '_', forced_separator: true)
|
147
|
+
RUBY
|
148
|
+
end
|
149
|
+
.cmdlet do
|
150
|
+
name :title
|
151
|
+
description "Title case the characters in the given 'string'"
|
152
|
+
result 'value converted to title case'
|
153
|
+
|
154
|
+
parameter :value, 'value - to be converted', param_type: 'String|Int'
|
155
|
+
|
156
|
+
ruby <<-'RUBY'
|
157
|
+
tokenizer.parse(value,
|
158
|
+
separator: ' ',
|
159
|
+
preserve_case: true,
|
160
|
+
compress_prefix_numerals: false,
|
161
|
+
compress_suffix_numerals: false)
|
162
|
+
.titleize
|
163
|
+
RUBY
|
164
|
+
end
|
165
|
+
.cmdlet do
|
166
|
+
name :upper
|
167
|
+
description "Upper case the characters in the given 'string'"
|
168
|
+
result 'value converted to upper case'
|
169
|
+
|
170
|
+
parameter :value, 'value - to be converted', param_type: 'String|Int'
|
171
|
+
|
172
|
+
ruby <<-'RUBY'
|
173
|
+
return '' if value.nil?
|
174
|
+
|
175
|
+
value.upcase
|
176
|
+
RUBY
|
177
|
+
end
|
178
|
+
.generate
|
179
|
+
.debug
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
# format_as
|
184
|
+
# upper
|
@@ -0,0 +1,126 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
KManager.action :comparison_commands do
|
4
|
+
action do
|
5
|
+
CmdletDirector
|
6
|
+
.init(k_builder, category: :comparison)
|
7
|
+
.cmdlet do
|
8
|
+
name :and
|
9
|
+
description 'Return true if **all of** the given values are truthy.'
|
10
|
+
result 'return true when every value is truthy'
|
11
|
+
|
12
|
+
parameter :values, 'list of values (via *splat) to be checked via AND condition', splat: '*', param_type: 'Object'
|
13
|
+
|
14
|
+
ruby <<-RUBY
|
15
|
+
values.all? { |value| value }
|
16
|
+
RUBY
|
17
|
+
end
|
18
|
+
.cmdlet do
|
19
|
+
name :default
|
20
|
+
description 'Return true if **all of** the given values are truthy.'
|
21
|
+
result 'return true when every value is truthy'
|
22
|
+
|
23
|
+
parameter :values, 'one or more paramaters that may or may not contain nil', splat: '*', param_type: 'Object'
|
24
|
+
|
25
|
+
ruby <<-RUBY
|
26
|
+
default_value = values[-1]
|
27
|
+
|
28
|
+
find_value = values[0..-2].find { |value| !value.nil? }
|
29
|
+
|
30
|
+
find_value || default_value
|
31
|
+
RUBY
|
32
|
+
|
33
|
+
end
|
34
|
+
.cmdlet do
|
35
|
+
name :eq
|
36
|
+
description 'Return true if two values are equal'
|
37
|
+
result 'return truthy value if left hand side equals right hand side'
|
38
|
+
|
39
|
+
parameter :lhs, 'lhs - left hand side value', param_type: 'Object'
|
40
|
+
parameter :rhs, 'rhs - right hand side value', param_type: 'Object'
|
41
|
+
|
42
|
+
ruby <<-RUBY
|
43
|
+
lhs = lhs.to_s if lhs.is_a?(Symbol)
|
44
|
+
rhs = rhs.to_s if rhs.is_a?(Symbol)
|
45
|
+
|
46
|
+
lhs == rhs
|
47
|
+
RUBY
|
48
|
+
end
|
49
|
+
.cmdlet do
|
50
|
+
name :gt
|
51
|
+
description 'Return true if left hand side GREATER THAN right hand side'
|
52
|
+
result 'truthy value if left hand side GREATER THAN right hand side'
|
53
|
+
|
54
|
+
parameter :lhs, 'lhs - left hand side value', param_type: 'Object'
|
55
|
+
parameter :rhs, 'rhs - right hand side value', param_type: 'Object'
|
56
|
+
|
57
|
+
ruby <<-RUBY
|
58
|
+
lhs > rhs
|
59
|
+
RUBY
|
60
|
+
end
|
61
|
+
.cmdlet do
|
62
|
+
name :gte
|
63
|
+
description 'Return true if left hand side GREATER THAN or EQUAL TO right hand side'
|
64
|
+
result 'truthy value if left hand side GREATER THAN or EQUAL TO right hand side'
|
65
|
+
|
66
|
+
parameter :lhs, 'lhs - left hand side value', param_type: 'Object'
|
67
|
+
parameter :rhs, 'rhs - right hand side value', param_type: 'Object'
|
68
|
+
|
69
|
+
ruby <<-RUBY
|
70
|
+
lhs >= rhs
|
71
|
+
RUBY
|
72
|
+
end
|
73
|
+
.cmdlet do
|
74
|
+
name :lt
|
75
|
+
description 'Return true if left hand side LESS THAN right hand side'
|
76
|
+
result 'truthy value if left hand side LESS THAN right hand side'
|
77
|
+
|
78
|
+
parameter :lhs, 'lhs - left hand side value', param_type: 'Object'
|
79
|
+
parameter :rhs, 'rhs - right hand side value', param_type: 'Object'
|
80
|
+
|
81
|
+
ruby <<-RUBY
|
82
|
+
lhs < rhs
|
83
|
+
RUBY
|
84
|
+
end
|
85
|
+
.cmdlet do
|
86
|
+
name :lte
|
87
|
+
description 'Return true if left hand side LESS THAN or EQUAL TO right hand side'
|
88
|
+
result 'truthy value if left hand side LESS THAN or EQUAL TO right hand side'
|
89
|
+
|
90
|
+
parameter :lhs, 'lhs - left hand side value', param_type: 'Object'
|
91
|
+
parameter :rhs, 'rhs - right hand side value', param_type: 'Object'
|
92
|
+
|
93
|
+
ruby <<-RUBY
|
94
|
+
lhs <= rhs
|
95
|
+
RUBY
|
96
|
+
end
|
97
|
+
.cmdlet do
|
98
|
+
name :ne
|
99
|
+
description 'Return true if left hand side is NOT equal to right hand side'
|
100
|
+
result 'truthy value if left hand side is NOT equal to right hand side'
|
101
|
+
|
102
|
+
parameter :lhs, 'lhs - left hand side value', param_type: 'Object'
|
103
|
+
parameter :rhs, 'rhs - right hand side value', param_type: 'Object'
|
104
|
+
|
105
|
+
ruby <<-RUBY
|
106
|
+
lhs = lhs.to_s if lhs.is_a?(Symbol)
|
107
|
+
rhs = rhs.to_s if rhs.is_a?(Symbol)
|
108
|
+
|
109
|
+
lhs != rhs
|
110
|
+
RUBY
|
111
|
+
end
|
112
|
+
.cmdlet do
|
113
|
+
name :or
|
114
|
+
description 'Return true if any value is truthy.'
|
115
|
+
result 'return true when first value is truthy'
|
116
|
+
|
117
|
+
parameter :values, 'list of values (via *splat) to be checked via AND condition', splat: '*', param_type: 'Object'
|
118
|
+
|
119
|
+
ruby <<-RUBY
|
120
|
+
values.any? { |value| value }
|
121
|
+
RUBY
|
122
|
+
end
|
123
|
+
.generate
|
124
|
+
.debug
|
125
|
+
end
|
126
|
+
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
KManager.action :inflection_commands do
|
4
|
+
action do
|
5
|
+
CmdletDirector
|
6
|
+
.init(k_builder, category: :inflection)
|
7
|
+
.cmdlet do
|
8
|
+
name :ordinal
|
9
|
+
description 'The suffix that should be added to a number to denote the position in an ordered sequence such as 1st, 2nd, 3rd, 4th'
|
10
|
+
result 'ordinal suffix that would be required for a number'
|
11
|
+
|
12
|
+
parameter :value, 'value - numeric value', param_type: 'String|Int'
|
13
|
+
|
14
|
+
ruby <<-RUBY
|
15
|
+
return '' if value.nil?
|
16
|
+
|
17
|
+
value = value.to_i if value.is_a? String
|
18
|
+
|
19
|
+
value.ordinal
|
20
|
+
RUBY
|
21
|
+
end
|
22
|
+
.cmdlet do
|
23
|
+
name :ordinalize
|
24
|
+
description 'Turns a number into an ordinal string used to denote the position in an ordered sequence such as 1st, 2nd, 3rd, 4th.'
|
25
|
+
result 'number value turned to 1st, 2nd, 3rd, 4th etc.'
|
26
|
+
|
27
|
+
parameter :value, 'value - numeric value', param_type: 'Int'
|
28
|
+
|
29
|
+
ruby <<-RUBY
|
30
|
+
return '' if value.nil?
|
31
|
+
|
32
|
+
value = value.to_i if value.is_a? String
|
33
|
+
|
34
|
+
value.ordinalize
|
35
|
+
RUBY
|
36
|
+
end
|
37
|
+
.cmdlet do
|
38
|
+
name :pluralize
|
39
|
+
description 'Returns the plural form of the word in the string'
|
40
|
+
result 'value in plural form'
|
41
|
+
|
42
|
+
parameter :value, 'value - value to pluralize', param_type: 'String'
|
43
|
+
|
44
|
+
ruby <<-RUBY
|
45
|
+
return '' if value.nil?
|
46
|
+
|
47
|
+
value = value.to_s if value.is_a?(Symbol)
|
48
|
+
|
49
|
+
value.pluralize
|
50
|
+
RUBY
|
51
|
+
end
|
52
|
+
.cmdlet do
|
53
|
+
name :pluralize_by_number
|
54
|
+
description 'Returns the plural form of the word based on a count'
|
55
|
+
result 'value and number are used to calculate plural/singular form'
|
56
|
+
|
57
|
+
parameter :value, 'value - value to pluralize', param_type: 'String'
|
58
|
+
parameter :count, 'count used to determine pluralization', param_type: 'Int'
|
59
|
+
parameter :format, '(Optional) what format should output be. :word, :number_word'
|
60
|
+
|
61
|
+
ruby <<-'RUBY'
|
62
|
+
return '' if value.nil?
|
63
|
+
|
64
|
+
count = count.to_i if count.is_a? String
|
65
|
+
format = :word if format.nil?
|
66
|
+
|
67
|
+
case format.to_sym
|
68
|
+
when :number_word, :number_and_word
|
69
|
+
"#{count} #{value.pluralize(count)}"
|
70
|
+
else # aka :word
|
71
|
+
value.pluralize(count)
|
72
|
+
end
|
73
|
+
RUBY
|
74
|
+
end
|
75
|
+
.cmdlet do
|
76
|
+
name :singularize
|
77
|
+
description 'The reverse of #pluralize, returns the singular form of a word in a string'
|
78
|
+
result 'plural value turned to singular value'
|
79
|
+
|
80
|
+
parameter :value, 'value - value to singularized', param_type: 'String'
|
81
|
+
|
82
|
+
ruby <<-RUBY
|
83
|
+
return '' if value.nil?
|
84
|
+
|
85
|
+
value = value.to_s if value.is_a?(Symbol)
|
86
|
+
|
87
|
+
value.singularize
|
88
|
+
RUBY
|
89
|
+
end
|
90
|
+
.generate
|
91
|
+
.debug
|
92
|
+
end
|
93
|
+
end
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,40 @@
|
|
1
|
+
# [0.2.0](https://github.com/klueless-io/cmdlet/compare/v0.1.2...v0.2.0) (2022-07-10)
|
2
|
+
|
3
|
+
|
4
|
+
### Features
|
5
|
+
|
6
|
+
* add inflection cmdlets ([55bb73f](https://github.com/klueless-io/cmdlet/commit/55bb73fe3420096a1d4edd85d207529507c088db))
|
7
|
+
|
8
|
+
## [0.1.2](https://github.com/klueless-io/cmdlet/compare/v0.1.1...v0.1.2) (2022-07-10)
|
9
|
+
|
10
|
+
|
11
|
+
### Bug Fixes
|
12
|
+
|
13
|
+
* add comparison :or ([633633d](https://github.com/klueless-io/cmdlet/commit/633633d2a22b98a0de1acf6257feb3603a2f2c39))
|
14
|
+
* add comparison :or, :and, :lt, :lte, :gt, :gte, :ne, :eq, :default ([000cb1a](https://github.com/klueless-io/cmdlet/commit/000cb1a3cbd643abcb5dac6828972ec94c9f53a8))
|
15
|
+
|
16
|
+
## [0.1.1](https://github.com/klueless-io/cmdlet/compare/v0.1.0...v0.1.1) (2022-07-10)
|
17
|
+
|
18
|
+
|
19
|
+
### Bug Fixes
|
20
|
+
|
21
|
+
* add specs ([80f384f](https://github.com/klueless-io/cmdlet/commit/80f384f9f7cd1c1ea67396bb12d3119c433ea139))
|
22
|
+
|
23
|
+
# [0.1.0](https://github.com/klueless-io/cmdlet/compare/v0.0.7...v0.1.0) (2022-07-09)
|
24
|
+
|
25
|
+
|
26
|
+
### Features
|
27
|
+
|
28
|
+
* generate commandlets ([a61948e](https://github.com/klueless-io/cmdlet/commit/a61948e285d488d3aab68a9ef3bd0c136b87170f))
|
29
|
+
|
30
|
+
## [0.0.7](https://github.com/klueless-io/cmdlet/compare/v0.0.6...v0.0.7) (2022-07-09)
|
31
|
+
|
32
|
+
|
33
|
+
### Bug Fixes
|
34
|
+
|
35
|
+
* add category director ([3b72b72](https://github.com/klueless-io/cmdlet/commit/3b72b72d9f739c9a3711f14a640bb6d527e17140))
|
36
|
+
* add category director ([cea0f1a](https://github.com/klueless-io/cmdlet/commit/cea0f1ae37bfbb67d634f18cf1d315a80c1f6082))
|
37
|
+
|
1
38
|
## [0.0.6](https://github.com/klueless-io/cmdlet/compare/v0.0.5...v0.0.6) (2022-07-08)
|
2
39
|
|
3
40
|
|
data/Guardfile
CHANGED
@@ -19,7 +19,7 @@ group :green_pass_then_cop, halt_on_fail: true do
|
|
19
19
|
# Ruby files
|
20
20
|
ruby = dsl.ruby
|
21
21
|
dsl.watch_spec_files_for(ruby.lib_files)
|
22
|
-
watch(%r{^lib//(.+)\.rb$}) { |m| "spec
|
22
|
+
watch(%r{^lib//(.+)\.rb$}) { |m| "spec/**/#{m[1]}_spec.rb" }
|
23
23
|
watch(%r{^lib//commands/(.+)\.rb$}) { |m| "spec/unit/commands/#{m[1]}_spec.rb" }
|
24
24
|
end
|
25
25
|
|
data/lib/cmdlet/_.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'array/join'
|
4
|
+
require_relative 'array/join_post'
|
5
|
+
require_relative 'array/join_pre'
|
6
|
+
require_relative 'case/back_slash'
|
7
|
+
require_relative 'case/camel'
|
8
|
+
require_relative 'case/constant'
|
9
|
+
require_relative 'case/dash'
|
10
|
+
require_relative 'case/dot'
|
11
|
+
require_relative 'case/double_colon'
|
12
|
+
require_relative 'case/human'
|
13
|
+
require_relative 'case/lamel'
|
14
|
+
require_relative 'case/lower'
|
15
|
+
require_relative 'case/sentence'
|
16
|
+
require_relative 'case/slash'
|
17
|
+
require_relative 'case/snake'
|
18
|
+
require_relative 'case/title'
|
19
|
+
require_relative 'case/upper'
|
20
|
+
require_relative 'comparison/and'
|
21
|
+
require_relative 'comparison/default'
|
22
|
+
require_relative 'comparison/eq'
|
23
|
+
require_relative 'comparison/gt'
|
24
|
+
require_relative 'comparison/gte'
|
25
|
+
require_relative 'comparison/lt'
|
26
|
+
require_relative 'comparison/lte'
|
27
|
+
require_relative 'comparison/ne'
|
28
|
+
require_relative 'comparison/or'
|
29
|
+
require_relative 'inflection/ordinal'
|
30
|
+
require_relative 'inflection/ordinalize'
|
31
|
+
require_relative 'inflection/pluralize'
|
32
|
+
require_relative 'inflection/pluralize_by_number'
|
33
|
+
require_relative 'inflection/singularize'
|
data/lib/cmdlet/array/join.rb
CHANGED
@@ -1,22 +1,20 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# reference: https://github.com/rails/rails/blob/master/activesupport/lib/active_support/inflector/methods.rb
|
4
|
-
|
5
3
|
module Cmdlet
|
6
4
|
# Array handling routines, eg. join, join_prefix, join_post
|
7
5
|
module Array
|
8
6
|
# Join: join an array of values with separator as a string
|
9
|
-
class Join <
|
7
|
+
class Join < Cmdlet::BaseCmdlet
|
10
8
|
#
|
11
|
-
# @param [String|Int]
|
12
|
-
# @
|
13
|
-
|
14
|
-
|
9
|
+
# @param [String|Int] values - array of values to join
|
10
|
+
# @param [String] separator - separator between values, defaults to comma
|
11
|
+
# @return [String] new String formed by joining the array elements with seperator
|
12
|
+
def call(values, separator = ',')
|
13
|
+
return false if values.nil? || values.length.zero?
|
15
14
|
|
16
|
-
values =
|
17
|
-
return '' if
|
15
|
+
values = values.reject(&:blank?)
|
16
|
+
return '' if values.length.zero?
|
18
17
|
|
19
|
-
separator = ','
|
20
18
|
values.join(separator)
|
21
19
|
end
|
22
20
|
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Cmdlet
|
4
|
+
# Array handling routines, eg. join, join_prefix, join_post
|
5
|
+
module Array
|
6
|
+
# JoinPost: join an array of values with separator as a string and using the separator at the end of string
|
7
|
+
class JoinPost < Cmdlet::BaseCmdlet
|
8
|
+
#
|
9
|
+
# @param [String|Int] values - array of values to join
|
10
|
+
# @param [String] separator - separator between values, defaults to comma
|
11
|
+
# @return [String]
|
12
|
+
def call(values, separator = ',')
|
13
|
+
return '' if values.nil? || !values.is_a?(::Array)
|
14
|
+
|
15
|
+
values = values.reject(&:blank?)
|
16
|
+
return '' if values.length.zero?
|
17
|
+
|
18
|
+
"#{values.join(separator)}#{separator}"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|