cmdlet 0.0.6 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.builders/.templates/FUNCTIONS.MD +19 -0
- data/.builders/.templates/cmdlet.rb +26 -0
- data/.builders/.templates/cmdlet_spec.rb +22 -0
- data/.builders/.templates/require_all_cmdlets.rb +5 -0
- data/.builders/_.rb +11 -1
- data/.builders/boot.rb +6 -3
- data/.builders/data/categories.json +28 -0
- data/.builders/data/cmdlets/array.json +121 -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 +39 -0
- data/.builders/director/cmdlet_builder.rb +67 -0
- data/.builders/director/cmdlet_child.rb +39 -0
- data/.builders/director/cmdlet_dao.rb +29 -0
- data/.builders/director/cmdlet_director.rb +60 -0
- data/.builders/director/dao.rb +16 -0
- data/.builders/documents/commands.rb +222 -28
- 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/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 +19 -0
- data/lib/cmdlet/all_commands.rb +3 -0
- data/lib/cmdlet/array/join.rb +22 -0
- 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/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 +46 -5
- data/.builders/documents/_.rb +0 -4
- data/.builders/documents/categories.rb +0 -24
- data/.builders/documents/functions.rb +0 -226
@@ -1,6 +1,6 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
|
2
3
|
def category_blueprint
|
3
|
-
|
4
4
|
fn_builder
|
5
5
|
.init
|
6
6
|
.category(:array , active: 0 , title: 'Array' , description: 'Functions for working with Array')
|
@@ -24,11 +24,9 @@ def category_blueprint
|
|
24
24
|
.category(:regex , active: 0 , title: 'Regex' , description: 'Functions for working with Regex')
|
25
25
|
.category(:string , active: 0 , title: 'String' , description: 'Functions for working with String')
|
26
26
|
.category(:url , active: 0 , title: 'Url' , description: 'Functions for working with Url')
|
27
|
-
|
28
27
|
end
|
29
28
|
|
30
29
|
def function_blueprint
|
31
|
-
|
32
30
|
fn_builder
|
33
31
|
.init
|
34
32
|
.for_category(:array)
|
@@ -41,11 +39,11 @@ def function_blueprint
|
|
41
39
|
.for_category(:html)
|
42
40
|
.for_category(:i18n)
|
43
41
|
.for_category(:inflection)
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
42
|
+
.function(:ordinal)
|
43
|
+
.function(:ordinalize)
|
44
|
+
.function(:pluralize_by_number)
|
45
|
+
.function(:pluralize)
|
46
|
+
.function(:singularize)
|
49
47
|
.for_category(:logging)
|
50
48
|
.for_category(:markdown)
|
51
49
|
.for_category(:match)
|
@@ -57,10 +55,9 @@ def function_blueprint
|
|
57
55
|
.for_category(:regex)
|
58
56
|
.for_category(:string)
|
59
57
|
.for_category(:url)
|
60
|
-
|
61
58
|
end
|
62
59
|
|
63
60
|
# {{arrayify}}
|
64
61
|
# Cast the given value to an array.
|
65
62
|
# {{before}}
|
66
|
-
# Return all of the items in the collection before the specified count. Opposite of after.
|
63
|
+
# Return all of the items in the collection before the specified count. Opposite of after.
|
@@ -1,121 +1,121 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
KManager.action :bootstrap do
|
2
4
|
action do
|
3
5
|
application_name = :cmdlet
|
4
6
|
|
5
7
|
# Ruby Gem Bootstrap
|
6
8
|
director = KDirector::Dsls::RubyGemDsl
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
run_command("git add .; git commit -m 'chore: #{self.options.description.downcase}'; git push")
|
118
|
-
end
|
9
|
+
.init(k_builder,
|
10
|
+
on_exist: :skip, # %i[skip write compare]
|
11
|
+
on_action: :queue # %i[queue execute]
|
12
|
+
)
|
13
|
+
.data(
|
14
|
+
ruby_version: '2.7',
|
15
|
+
application: application_name,
|
16
|
+
application_description: 'Cmdlet provides a set of functions (wrapped in the command pattern) that perform simple actions',
|
17
|
+
application_lib_path: application_name.to_s,
|
18
|
+
application_lib_namespace: 'Cmdlet',
|
19
|
+
namespaces: ['Cmdlet'],
|
20
|
+
author: 'David Cruwys',
|
21
|
+
author_email: 'david@ideasmen.com.au',
|
22
|
+
initial_semver: '0.0.1',
|
23
|
+
main_story: 'As a Developer, I want to use simple categorized functions so that I can easily add commonplace functionality to my application',
|
24
|
+
copyright_date: '2022',
|
25
|
+
website: 'http://appydave.com/gems/cmdlet'
|
26
|
+
)
|
27
|
+
.github(
|
28
|
+
active: false,
|
29
|
+
repo_name: application_name
|
30
|
+
) do
|
31
|
+
create_repository
|
32
|
+
# delete_repository
|
33
|
+
# list_repositories
|
34
|
+
open_repository
|
35
|
+
# run_command('git init')
|
36
|
+
end
|
37
|
+
.blueprint(
|
38
|
+
active: false,
|
39
|
+
name: :bin_hook,
|
40
|
+
description: 'initialize repository',
|
41
|
+
on_exist: :write
|
42
|
+
) do
|
43
|
+
cd(:app)
|
44
|
+
|
45
|
+
run_template_script('bin/runonce/git-setup.sh', dom: dom)
|
46
|
+
|
47
|
+
add('.githooks/commit-msg').run_command('chmod +x .githooks/commit-msg')
|
48
|
+
add('.githooks/pre-commit').run_command('chmod +x .githooks/pre-commit')
|
49
|
+
|
50
|
+
add('.gitignore')
|
51
|
+
|
52
|
+
run_command('git config core.hooksPath .githooks') # enable sharable githooks (developer needs to turn this on before editing rep)
|
53
|
+
|
54
|
+
run_command("git add .; git commit -m 'chore: #{options.description.downcase}'; git push")
|
55
|
+
run_command("gh repo edit -d \"#{dom[:application_description]}\"")
|
56
|
+
end
|
57
|
+
.package_json(
|
58
|
+
active: false,
|
59
|
+
name: :package_json,
|
60
|
+
description: 'Set up the package.json file for semantic versioning'
|
61
|
+
) do
|
62
|
+
add('package.json', dom: dom)
|
63
|
+
.play_actions
|
64
|
+
|
65
|
+
add_script('release', 'semantic-release')
|
66
|
+
.sort
|
67
|
+
.development
|
68
|
+
.npm_add_group('semver-ruby')
|
69
|
+
|
70
|
+
run_command("git add .; git commit -m 'chore: #{options.description.downcase}'; git push")
|
71
|
+
end
|
72
|
+
.blueprint(
|
73
|
+
active: false,
|
74
|
+
name: :opinionated,
|
75
|
+
description: 'opinionated GEM files',
|
76
|
+
on_exist: :write
|
77
|
+
) do
|
78
|
+
cd(:app)
|
79
|
+
|
80
|
+
add('bin/setup')
|
81
|
+
add('bin/console')
|
82
|
+
|
83
|
+
add("lib/#{typed_dom.application}.rb" , template_file: 'lib/applet_name.rb' , dom: dom)
|
84
|
+
add("lib/#{typed_dom.application}/version.rb" , template_file: 'lib/applet_name/version.rb' , dom: dom)
|
85
|
+
|
86
|
+
add('spec/spec_helper.rb')
|
87
|
+
add("spec/#{typed_dom.application}_spec.rb" , template_file: 'spec/applet_name_spec.rb', dom: dom)
|
88
|
+
|
89
|
+
add("#{typed_dom.application}.gemspec" , template_file: 'applet_name.gemspec', dom: dom)
|
90
|
+
add('Gemfile', dom: dom)
|
91
|
+
add('Guardfile', dom: dom)
|
92
|
+
add('Rakefile', dom: dom)
|
93
|
+
add('.rspec', dom: dom)
|
94
|
+
add('.rubocop.yml', dom: dom)
|
95
|
+
add('README.md', dom: dom)
|
96
|
+
add('CODE_OF_CONDUCT.md', dom: dom)
|
97
|
+
add('LICENSE.txt', dom: dom)
|
98
|
+
|
99
|
+
run_command('rubocop -a')
|
100
|
+
|
101
|
+
run_command("git add .; git commit -m 'chore: #{options.description.downcase}'; git push")
|
102
|
+
end
|
103
|
+
.blueprint(
|
104
|
+
active: true,
|
105
|
+
name: :ci_cd,
|
106
|
+
description: 'github actions (CI/CD)',
|
107
|
+
on_exist: :write
|
108
|
+
) do
|
109
|
+
cd(:app)
|
110
|
+
|
111
|
+
run_command('gh secret set SLACK_WEBHOOK --body "$SLACK_REPO_WEBHOOK"')
|
112
|
+
run_command('gh secret set GEM_HOST_API_KEY --body "$GEM_HOST_API_KEY"')
|
113
|
+
|
114
|
+
add('.github/workflows/main.yml')
|
115
|
+
add('.releaserc.json')
|
116
|
+
|
117
|
+
run_command("git add .; git commit -m 'chore: #{options.description.downcase}'; git push")
|
118
|
+
end
|
119
119
|
|
120
120
|
director.play_actions
|
121
121
|
# director.builder.logit
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
KManager.action :categories do
|
4
|
+
action do
|
5
|
+
CategoryDirector
|
6
|
+
.init(k_builder)
|
7
|
+
.category(:case , 'Tokenize and apply case and/or separator')
|
8
|
+
.category(:comparison , 'Comparison helpers, eg. or, and, equal, not equal, less than, greater than etc.')
|
9
|
+
.category(:inflection , 'Inflection handling routines, eg. pluralize, singular, ordinalize')
|
10
|
+
.category(:string , 'String handling helpers')
|
11
|
+
.category(:array , 'Array handling routines, eg. join, join_prefix, join_post')
|
12
|
+
.category(:transform , 'Tokenize and apply case and/or separator')
|
13
|
+
.save_categories
|
14
|
+
.generate
|
15
|
+
end
|
16
|
+
end
|
@@ -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,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
|