cmdlet 0.1.2 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4aaf22abcff261a22b71b4c4adeaf77dd8d629836936eabb1b20b2d8a61b3a28
4
- data.tar.gz: 4d249fee0dd48b4774881e16bcc92b303f788e45b22c54c14a321a70468bcabf
3
+ metadata.gz: dc4888cd594af0dd224a836be55e28d9b6cdf153ac89e770807d412b14d11982
4
+ data.tar.gz: 00b2044a9a53f53afbe109a443aabd7cc38db54782fd1a1eebfbdc563db3de7c
5
5
  SHA512:
6
- metadata.gz: ab39c705f59887093ecbf3a8ad2ec66f133bf14048f544b142b3de324fdb25006dfa19bb66efdf5e281d0167bac8b4bd2958769cff3ad8879515f833f24fa5d5
7
- data.tar.gz: e78c0098b63350dfcc77bb7c6c50d902b8da963a9fc8531639a5c6835df4fdae3158b8518f2efd2f87a2fda9dfd9fb3a573f774159c04fad451dca50da09ac43
6
+ metadata.gz: f7470c8c5cc637bfc48aa1e5d9a63d73748831e71d323cdf3a09d2cb1b5b0e8e40970300072eafbbe00976334d7021e3e22ce66f5626b4983faa2d02f5e4ca70
7
+ data.tar.gz: e04137866c533b774510d0964be0a27f98110c23237da9d55b8c560d371f1a32d55e8e2af67799b0f58b3240434b1fb7b46f40915cb1baacf4adcfb5f037a496
@@ -0,0 +1,129 @@
1
+ {
2
+ "category_key": "inflection",
3
+ "cmdlets": [
4
+ {
5
+ "name": "ordinal",
6
+ "description": "The suffix that should be added to a number to denote the position in an ordered sequence such as 1st, 2nd, 3rd, 4th",
7
+ "result": "ordinal suffix that would be required for a number",
8
+ "category": "inflection",
9
+ "category_description": "Inflection handling routines, eg. pluralize, singular, ordinalize",
10
+ "base_class_require": null,
11
+ "base_class": null,
12
+ "parameters": [
13
+ {
14
+ "name": "value",
15
+ "description": "value - numeric value",
16
+ "splat": null,
17
+ "default": null,
18
+ "param_type": "String|Int"
19
+ }
20
+ ],
21
+ "examples": [
22
+
23
+ ],
24
+ "ruby": " return '' if value.nil?\n\n value = value.to_i if value.is_a? String\n\n value.ordinal\n"
25
+ },
26
+ {
27
+ "name": "ordinalize",
28
+ "description": "Turns a number into an ordinal string used to denote the position in an ordered sequence such as 1st, 2nd, 3rd, 4th.",
29
+ "result": "number value turned to 1st, 2nd, 3rd, 4th etc.",
30
+ "category": "inflection",
31
+ "category_description": "Inflection handling routines, eg. pluralize, singular, ordinalize",
32
+ "base_class_require": null,
33
+ "base_class": null,
34
+ "parameters": [
35
+ {
36
+ "name": "value",
37
+ "description": "value - numeric value",
38
+ "splat": null,
39
+ "default": null,
40
+ "param_type": "Int"
41
+ }
42
+ ],
43
+ "examples": [
44
+
45
+ ],
46
+ "ruby": " return '' if value.nil?\n\n value = value.to_i if value.is_a? String\n\n value.ordinalize\n"
47
+ },
48
+ {
49
+ "name": "pluralize",
50
+ "description": "Returns the plural form of the word in the string",
51
+ "result": "value in plural form",
52
+ "category": "inflection",
53
+ "category_description": "Inflection handling routines, eg. pluralize, singular, ordinalize",
54
+ "base_class_require": null,
55
+ "base_class": null,
56
+ "parameters": [
57
+ {
58
+ "name": "value",
59
+ "description": "value - value to pluralize",
60
+ "splat": null,
61
+ "default": null,
62
+ "param_type": "String"
63
+ }
64
+ ],
65
+ "examples": [
66
+
67
+ ],
68
+ "ruby": " return '' if value.nil?\n\n value = value.to_s if value.is_a?(Symbol)\n\n value.pluralize\n"
69
+ },
70
+ {
71
+ "name": "pluralize_by_number",
72
+ "description": "Returns the plural form of the word based on a count",
73
+ "result": "value and number are used to calculate plural/singular form",
74
+ "category": "inflection",
75
+ "category_description": "Inflection handling routines, eg. pluralize, singular, ordinalize",
76
+ "base_class_require": null,
77
+ "base_class": null,
78
+ "parameters": [
79
+ {
80
+ "name": "value",
81
+ "description": "value - value to pluralize",
82
+ "splat": null,
83
+ "default": null,
84
+ "param_type": "String"
85
+ },
86
+ {
87
+ "name": "count",
88
+ "description": "count used to determine pluralization",
89
+ "splat": null,
90
+ "default": null,
91
+ "param_type": "Int"
92
+ },
93
+ {
94
+ "name": "format",
95
+ "description": "(Optional) what format should output be. :word, :number_word",
96
+ "splat": null,
97
+ "default": null,
98
+ "param_type": "String"
99
+ }
100
+ ],
101
+ "examples": [
102
+
103
+ ],
104
+ "ruby": " return '' if value.nil?\n\n count = count.to_i if count.is_a? String\n format = :word if format.nil?\n\n case format.to_sym\n when :number_word, :number_and_word\n \"#{count} #{value.pluralize(count)}\"\n else # aka :word\n value.pluralize(count)\n end\n"
105
+ },
106
+ {
107
+ "name": "singularize",
108
+ "description": "The reverse of #pluralize, returns the singular form of a word in a string",
109
+ "result": "plural value turned to singular value",
110
+ "category": "inflection",
111
+ "category_description": "Inflection handling routines, eg. pluralize, singular, ordinalize",
112
+ "base_class_require": null,
113
+ "base_class": null,
114
+ "parameters": [
115
+ {
116
+ "name": "value",
117
+ "description": "value - value to singularized",
118
+ "splat": null,
119
+ "default": null,
120
+ "param_type": "String"
121
+ }
122
+ ],
123
+ "examples": [
124
+
125
+ ],
126
+ "ruby": " return '' if value.nil?\n\n value = value.to_s if value.is_a?(Symbol)\n\n value.singularize\n"
127
+ }
128
+ ]
129
+ }
@@ -69,41 +69,3 @@ KManager.action :array_commands do
69
69
  .debug
70
70
  end
71
71
  end
72
-
73
- # result "return block when every value is truthy"
74
-
75
- # parameter('values', 'list of values (via *splat) to be checked via AND condition', splat: true)
76
-
77
- # example <<-TEXT
78
- # {{#if (and p1 p2 p3 p4 p5)}}
79
- # found
80
- # {{/if}}
81
- # TEXT
82
-
83
- # example <<-TEXT
84
- # {{#if (and name age)}}
85
- # {{name}}-{{age}}
86
- # {{else}}
87
- # no name or age
88
- # {{/if}}
89
- # TEXT
90
-
91
- # builder
92
- # .add_file('FUNCTIONS.md',
93
- # template_file: 'FUNCTIONS.md',
94
- # categories: categories.sort_by { |r| r.name },
95
- # functions: functions.sort_by { |r| [r.category, r.name] },
96
- # on_exist: :write)
97
-
98
- # add('all_commands.rb',
99
- # template_file: 'all_commands.rb',
100
- # commands: commands.sort_by { |r| [r.category, r.name] },
101
- # on_exist: :write)
102
-
103
- # cmdlets.each do |cmdlet|
104
-
105
- # add("#{cmdlet.category}/#{cmdlet.name}.rb",
106
- # cmdlet: cmdlet,
107
- # template_file: 'command.rb',
108
- # on_exist: :write)
109
- # end
@@ -124,41 +124,3 @@ KManager.action :comparison_commands do
124
124
  .debug
125
125
  end
126
126
  end
127
-
128
- # result "return block when every value is truthy"
129
-
130
- # parameter('values', 'list of values (via *splat) to be checked via AND condition', splat: true)
131
-
132
- # example <<-TEXT
133
- # {{#if (and p1 p2 p3 p4 p5)}}
134
- # found
135
- # {{/if}}
136
- # TEXT
137
-
138
- # example <<-TEXT
139
- # {{#if (and name age)}}
140
- # {{name}}-{{age}}
141
- # {{else}}
142
- # no name or age
143
- # {{/if}}
144
- # TEXT
145
-
146
- # builder
147
- # .add_file('FUNCTIONS.md',
148
- # template_file: 'FUNCTIONS.md',
149
- # categories: categories.sort_by { |r| r.name },
150
- # functions: functions.sort_by { |r| [r.category, r.name] },
151
- # on_exist: :write)
152
-
153
- # add('all_commands.rb',
154
- # template_file: 'all_commands.rb',
155
- # commands: commands.sort_by { |r| [r.category, r.name] },
156
- # on_exist: :write)
157
-
158
- # cmdlets.each do |cmdlet|
159
-
160
- # add("#{cmdlet.category}/#{cmdlet.name}.rb",
161
- # cmdlet: cmdlet,
162
- # template_file: 'command.rb',
163
- # on_exist: :write)
164
- # 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,11 @@
1
+ ## [0.1.2](https://github.com/klueless-io/cmdlet/compare/v0.1.1...v0.1.2) (2022-07-10)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * add comparison :or ([633633d](https://github.com/klueless-io/cmdlet/commit/633633d2a22b98a0de1acf6257feb3603a2f2c39))
7
+ * add comparison :or, :and, :lt, :lte, :gt, :gte, :ne, :eq, :default ([000cb1a](https://github.com/klueless-io/cmdlet/commit/000cb1a3cbd643abcb5dac6828972ec94c9f53a8))
8
+
1
9
  ## [0.1.1](https://github.com/klueless-io/cmdlet/compare/v0.1.0...v0.1.1) (2022-07-10)
2
10
 
3
11
 
data/lib/cmdlet/_.rb CHANGED
@@ -12,3 +12,8 @@ require_relative 'comparison/lt'
12
12
  require_relative 'comparison/lte'
13
13
  require_relative 'comparison/ne'
14
14
  require_relative 'comparison/or'
15
+ require_relative 'inflection/ordinal'
16
+ require_relative 'inflection/ordinalize'
17
+ require_relative 'inflection/pluralize'
18
+ require_relative 'inflection/pluralize_by_number'
19
+ require_relative 'inflection/singularize'
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Cmdlet
4
+ # Inflection handling routines, eg. pluralize, singular, ordinalize
5
+ module Inflection
6
+ # Ordinal: The suffix that should be added to a number to denote the position in an ordered sequence such as 1st, 2nd, 3rd, 4th
7
+ class Ordinal < Cmdlet::BaseCmdlet
8
+ #
9
+ # @param [String|Int] value - value - numeric value
10
+ # @return [String] ordinal suffix that would be required for a number
11
+ def call(value)
12
+ return '' if value.nil?
13
+
14
+ value = value.to_i if value.is_a? String
15
+
16
+ value.ordinal
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Cmdlet
4
+ # Inflection handling routines, eg. pluralize, singular, ordinalize
5
+ module Inflection
6
+ # Ordinalize: Turns a number into an ordinal string used to denote the position in an ordered sequence such as 1st, 2nd, 3rd, 4th.
7
+ class Ordinalize < Cmdlet::BaseCmdlet
8
+ #
9
+ # @param [Int] value - value - numeric value
10
+ # @return [String] number value turned to 1st, 2nd, 3rd, 4th etc.
11
+ def call(value)
12
+ return '' if value.nil?
13
+
14
+ value = value.to_i if value.is_a? String
15
+
16
+ value.ordinalize
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Cmdlet
4
+ # Inflection handling routines, eg. pluralize, singular, ordinalize
5
+ module Inflection
6
+ # Pluralize: Returns the plural form of the word in the string
7
+ class Pluralize < Cmdlet::BaseCmdlet
8
+ #
9
+ # @param [String] value - value - value to pluralize
10
+ # @return [String] value in plural form
11
+ def call(value)
12
+ return '' if value.nil?
13
+
14
+ value = value.to_s if value.is_a?(Symbol)
15
+
16
+ value.pluralize
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Cmdlet
4
+ # Inflection handling routines, eg. pluralize, singular, ordinalize
5
+ module Inflection
6
+ # PluralizeByNumber: Returns the plural form of the word based on a count
7
+ class PluralizeByNumber < Cmdlet::BaseCmdlet
8
+ #
9
+ # @param [String] value - value - value to pluralize
10
+ # @param [Int] count - count used to determine pluralization
11
+ # @param [String] format - (Optional) what format should output be. :word, :number_word
12
+ # @return [String] value and number are used to calculate plural/singular form
13
+ def call(value, count, format)
14
+ return '' if value.nil?
15
+
16
+ count = count.to_i if count.is_a? String
17
+ format = :word if format.nil?
18
+
19
+ case format.to_sym
20
+ when :number_word, :number_and_word
21
+ "#{count} #{value.pluralize(count)}"
22
+ else # aka :word
23
+ value.pluralize(count)
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Cmdlet
4
+ # Inflection handling routines, eg. pluralize, singular, ordinalize
5
+ module Inflection
6
+ # Singularize: The reverse of #pluralize, returns the singular form of a word in a string
7
+ class Singularize < Cmdlet::BaseCmdlet
8
+ #
9
+ # @param [String] value - value - value to singularized
10
+ # @return [String] plural value turned to singular value
11
+ def call(value)
12
+ return '' if value.nil?
13
+
14
+ value = value.to_s if value.is_a?(Symbol)
15
+
16
+ value.singularize
17
+ end
18
+ end
19
+ end
20
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Cmdlet
4
- VERSION = '0.1.2'
4
+ VERSION = '0.2.0'
5
5
  end
data/lib/cmdlet.rb CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  # require 'k_log'
4
4
  require 'k_config'
5
+ require 'active_support/core_ext/integer/inflections'
6
+
5
7
  require_relative 'cmdlet/version'
6
8
  require_relative 'cmdlet/configuration'
7
9
  require_relative 'cmdlet/base_cmdlet'
data/package-lock.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "cmdlet",
3
- "version": "0.1.2",
3
+ "version": "0.2.0",
4
4
  "lockfileVersion": 2,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "cmdlet",
9
- "version": "0.1.2",
9
+ "version": "0.2.0",
10
10
  "devDependencies": {
11
11
  "@klueless-js/semantic-release-rubygem": "github:klueless-js/semantic-release-rubygem",
12
12
  "@semantic-release/changelog": "^6.0.1",
data/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cmdlet",
3
- "version": "0.1.2",
3
+ "version": "0.2.0",
4
4
  "description": "Cmdlet provides a set of functions (wrapped in the command pattern) that perform simple actions",
5
5
  "scripts": {
6
6
  "release": "semantic-release"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cmdlet
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Cruwys
@@ -55,6 +55,7 @@ files:
55
55
  - ".builders/data/categories.json"
56
56
  - ".builders/data/cmdlets/array.json"
57
57
  - ".builders/data/cmdlets/comparison.json"
58
+ - ".builders/data/cmdlets/inflection.json"
58
59
  - ".builders/director/category_builder.rb"
59
60
  - ".builders/director/category_dao.rb"
60
61
  - ".builders/director/category_director.rb"
@@ -71,6 +72,7 @@ files:
71
72
  - ".builders/generators/30-commands-bak.rb"
72
73
  - ".builders/generators/cmdlets/array.rb"
73
74
  - ".builders/generators/cmdlets/comparison.rb"
75
+ - ".builders/generators/cmdlets/inflection.rb"
74
76
  - ".releaserc.json"
75
77
  - ".rspec"
76
78
  - ".rubocop.yml"
@@ -100,6 +102,11 @@ files:
100
102
  - lib/cmdlet/comparison/ne.rb
101
103
  - lib/cmdlet/comparison/or.rb
102
104
  - lib/cmdlet/configuration.rb
105
+ - lib/cmdlet/inflection/ordinal.rb
106
+ - lib/cmdlet/inflection/ordinalize.rb
107
+ - lib/cmdlet/inflection/pluralize.rb
108
+ - lib/cmdlet/inflection/pluralize_by_number.rb
109
+ - lib/cmdlet/inflection/singularize.rb
103
110
  - lib/cmdlet/string_tokenizer.rb
104
111
  - lib/cmdlet/version.rb
105
112
  - package-lock.json