cmdlet 0.0.7 → 0.2.1
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 +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,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Cmdlet
|
4
|
+
# Array handling routines, eg. join, join_prefix, join_post
|
5
|
+
module Array
|
6
|
+
# JoinPre: join an array of values with separator as a string and using the separator at the beginning of string
|
7
|
+
class JoinPre < 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
|
+
"#{separator}#{values.join(separator)}"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Cmdlet
|
4
|
+
# base cmdlet provides an interface for cmdlets
|
5
|
+
class BaseCmdlet
|
6
|
+
def call(value)
|
7
|
+
value
|
8
|
+
end
|
9
|
+
|
10
|
+
# String tokenizer will clean up a string so that
|
11
|
+
# all sorts of case formatted strings can be
|
12
|
+
# represented in a consistent fashion
|
13
|
+
def tokenizer
|
14
|
+
@_tokenizer ||= KConfig.configuration.cmdlet.tokenizer
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Cmdlet
|
4
|
+
# Tokenize and apply case and/or separator
|
5
|
+
module Case
|
6
|
+
# BackSlash: Convert to back slash notation
|
7
|
+
class BackSlash < Cmdlet::BaseCmdlet
|
8
|
+
#
|
9
|
+
# @param [String|Int] value - value - to be converted
|
10
|
+
# @return [String] value converted to back_slash case
|
11
|
+
def call(value)
|
12
|
+
tokenizer.parse(value, preserve_case: true, separator: '\\')
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Cmdlet
|
4
|
+
# Tokenize and apply case and/or separator
|
5
|
+
module Case
|
6
|
+
# Camel: Camel case the characters in the given 'string'
|
7
|
+
class Camel < Cmdlet::BaseCmdlet
|
8
|
+
#
|
9
|
+
# @param [String|Int] value - value - to be converted
|
10
|
+
# @return [String] value converted to camel case
|
11
|
+
def call(value)
|
12
|
+
tokenizer.parse(value).underscore.camelize
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Cmdlet
|
4
|
+
# Tokenize and apply case and/or separator
|
5
|
+
module Case
|
6
|
+
# Constant: Constant case the characters in the given 'string'
|
7
|
+
class Constant < Cmdlet::BaseCmdlet
|
8
|
+
#
|
9
|
+
# @param [String|Int] value - value - to be converted
|
10
|
+
# @return [String] value converted to constant case
|
11
|
+
def call(value)
|
12
|
+
tokenizer.parse(value, separator: '_').upcase
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Cmdlet
|
4
|
+
# Tokenize and apply case and/or separator
|
5
|
+
module Case
|
6
|
+
# Dash: Dash case the characters in the given 'string'
|
7
|
+
class Dash < Cmdlet::BaseCmdlet
|
8
|
+
#
|
9
|
+
# @param [String|Int] value - value - to be converted
|
10
|
+
# @return [String] value converted to dash case
|
11
|
+
def call(value)
|
12
|
+
tokenizer.parse(value)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Cmdlet
|
4
|
+
# Tokenize and apply case and/or separator
|
5
|
+
module Case
|
6
|
+
# Dot: Dot case the characters in the given 'string'
|
7
|
+
class Dot < Cmdlet::BaseCmdlet
|
8
|
+
#
|
9
|
+
# @param [String|Int] value - value - to be converted
|
10
|
+
# @return [String] value converted to dot case
|
11
|
+
def call(value)
|
12
|
+
tokenizer.parse(value, separator: '.')
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Cmdlet
|
4
|
+
# Tokenize and apply case and/or separator
|
5
|
+
module Case
|
6
|
+
# DoubleColon: Double colon case the characters in the given 'string'
|
7
|
+
class DoubleColon < Cmdlet::BaseCmdlet
|
8
|
+
#
|
9
|
+
# @param [String|Int] value - value - to be converted
|
10
|
+
# @return [String] value converted to double_colon case
|
11
|
+
def call(value)
|
12
|
+
tokenizer.parse(value, preserve_case: true, separator: '::')
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Cmdlet
|
4
|
+
# Tokenize and apply case and/or separator
|
5
|
+
module Case
|
6
|
+
# Human: Human case the characters in the given 'string'
|
7
|
+
class Human < Cmdlet::BaseCmdlet
|
8
|
+
#
|
9
|
+
# @param [String|Int] value - value - to be converted
|
10
|
+
# @return [String] value converted to human case
|
11
|
+
def call(value)
|
12
|
+
tokenizer.parse(value,
|
13
|
+
separator: ' ',
|
14
|
+
preserve_case: true,
|
15
|
+
compress_prefix_numerals: false,
|
16
|
+
compress_suffix_numerals: false).humanize
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Cmdlet
|
4
|
+
# Tokenize and apply case and/or separator
|
5
|
+
module Case
|
6
|
+
# Lamel: Lower camel case the characters in the given 'string'
|
7
|
+
class Lamel < Cmdlet::BaseCmdlet
|
8
|
+
#
|
9
|
+
# @param [String|Int] value - value - to be converted
|
10
|
+
# @return [String] value converted to lower camel case
|
11
|
+
def call(value)
|
12
|
+
tokenizer.parse(value, separator: '_').camelize(:lower)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Cmdlet
|
4
|
+
# Tokenize and apply case and/or separator
|
5
|
+
module Case
|
6
|
+
# Lower: Lower case the characters in the given 'string'
|
7
|
+
class Lower < Cmdlet::BaseCmdlet
|
8
|
+
#
|
9
|
+
# @param [String|Int] value - value - to be converted
|
10
|
+
# @return [String] value converted to lower case
|
11
|
+
def call(value)
|
12
|
+
return '' if value.nil?
|
13
|
+
|
14
|
+
value.downcase
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Cmdlet
|
4
|
+
# Tokenize and apply case and/or separator
|
5
|
+
module Case
|
6
|
+
# Sentence: Sentence case the characters in the given 'string'
|
7
|
+
class Sentence < Cmdlet::BaseCmdlet
|
8
|
+
#
|
9
|
+
# @param [String|Int] value - value - to be converted
|
10
|
+
# @return [String] value converted to sentence case
|
11
|
+
def call(value)
|
12
|
+
tokenizer.parse(value,
|
13
|
+
separator: ' ',
|
14
|
+
preserve_case: true,
|
15
|
+
compress_prefix_numerals: false,
|
16
|
+
compress_suffix_numerals: false).titleize
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Cmdlet
|
4
|
+
# Tokenize and apply case and/or separator
|
5
|
+
module Case
|
6
|
+
# Slash: Slash case the characters in the given 'string'
|
7
|
+
class Slash < Cmdlet::BaseCmdlet
|
8
|
+
#
|
9
|
+
# @param [String|Int] value - value - to be converted
|
10
|
+
# @return [String] value converted to slash case
|
11
|
+
def call(value)
|
12
|
+
tokenizer.parse(value, preserve_case: true, separator: '/')
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Cmdlet
|
4
|
+
# Tokenize and apply case and/or separator
|
5
|
+
module Case
|
6
|
+
# Snake: Snake case the characters in the given 'string'
|
7
|
+
class Snake < Cmdlet::BaseCmdlet
|
8
|
+
#
|
9
|
+
# @param [String|Int] value - value - to be converted
|
10
|
+
# @return [String] value converted to snake case
|
11
|
+
def call(value)
|
12
|
+
tokenizer.parse(value, separator: '_', forced_separator: true)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Cmdlet
|
4
|
+
# Tokenize and apply case and/or separator
|
5
|
+
module Case
|
6
|
+
# Title: Title case the characters in the given 'string'
|
7
|
+
class Title < Cmdlet::BaseCmdlet
|
8
|
+
#
|
9
|
+
# @param [String|Int] value - value - to be converted
|
10
|
+
# @return [String] value converted to title case
|
11
|
+
def call(value)
|
12
|
+
tokenizer.parse(value,
|
13
|
+
separator: ' ',
|
14
|
+
preserve_case: true,
|
15
|
+
compress_prefix_numerals: false,
|
16
|
+
compress_suffix_numerals: false)
|
17
|
+
.titleize
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Cmdlet
|
4
|
+
# Tokenize and apply case and/or separator
|
5
|
+
module Case
|
6
|
+
# Upper: Upper case the characters in the given 'string'
|
7
|
+
class Upper < Cmdlet::BaseCmdlet
|
8
|
+
#
|
9
|
+
# @param [String|Int] value - value - to be converted
|
10
|
+
# @return [String] value converted to upper case
|
11
|
+
def call(value)
|
12
|
+
return '' if value.nil?
|
13
|
+
|
14
|
+
value.upcase
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Cmdlet
|
4
|
+
# Comparison helpers, eg. or, and, equal, not equal, less than, greater than etc.
|
5
|
+
module Comparison
|
6
|
+
# And: Return true if **all of** the given values are truthy.
|
7
|
+
class And < Cmdlet::BaseCmdlet
|
8
|
+
#
|
9
|
+
# @param [Object] values - list of values (via *splat) to be checked via AND condition
|
10
|
+
# @return [String] return true when every value is truthy
|
11
|
+
def call(*values)
|
12
|
+
values.all? { |value| value }
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Cmdlet
|
4
|
+
# Comparison helpers, eg. or, and, equal, not equal, less than, greater than etc.
|
5
|
+
module Comparison
|
6
|
+
# Default: Return true if **all of** the given values are truthy.
|
7
|
+
class Default < Cmdlet::BaseCmdlet
|
8
|
+
#
|
9
|
+
# @param [Object] values - one or more paramaters that may or may not contain nil
|
10
|
+
# @return [String] return true when every value is truthy
|
11
|
+
def call(*values)
|
12
|
+
default_value = values[-1]
|
13
|
+
|
14
|
+
find_value = values[0..-2].find { |value| !value.nil? }
|
15
|
+
|
16
|
+
find_value || default_value
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Cmdlet
|
4
|
+
# Comparison helpers, eg. or, and, equal, not equal, less than, greater than etc.
|
5
|
+
module Comparison
|
6
|
+
# Eq: Return true if two values are equal
|
7
|
+
class Eq < Cmdlet::BaseCmdlet
|
8
|
+
#
|
9
|
+
# @param [Object] lhs - lhs - left hand side value
|
10
|
+
# @param [Object] rhs - rhs - right hand side value
|
11
|
+
# @return [String] return truthy value if left hand side equals right hand side
|
12
|
+
def call(lhs, rhs)
|
13
|
+
lhs = lhs.to_s if lhs.is_a?(Symbol)
|
14
|
+
rhs = rhs.to_s if rhs.is_a?(Symbol)
|
15
|
+
|
16
|
+
lhs == rhs
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Cmdlet
|
4
|
+
# Comparison helpers, eg. or, and, equal, not equal, less than, greater than etc.
|
5
|
+
module Comparison
|
6
|
+
# Gt: Return true if left hand side GREATER THAN right hand side
|
7
|
+
class Gt < Cmdlet::BaseCmdlet
|
8
|
+
#
|
9
|
+
# @param [Object] lhs - lhs - left hand side value
|
10
|
+
# @param [Object] rhs - rhs - right hand side value
|
11
|
+
# @return [String] truthy value if left hand side GREATER THAN right hand side
|
12
|
+
def call(lhs, rhs)
|
13
|
+
lhs > rhs
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Cmdlet
|
4
|
+
# Comparison helpers, eg. or, and, equal, not equal, less than, greater than etc.
|
5
|
+
module Comparison
|
6
|
+
# Gte: Return true if left hand side GREATER THAN or EQUAL TO right hand side
|
7
|
+
class Gte < Cmdlet::BaseCmdlet
|
8
|
+
#
|
9
|
+
# @param [Object] lhs - lhs - left hand side value
|
10
|
+
# @param [Object] rhs - rhs - right hand side value
|
11
|
+
# @return [String] truthy value if left hand side GREATER THAN or EQUAL TO right hand side
|
12
|
+
def call(lhs, rhs)
|
13
|
+
lhs >= rhs
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Cmdlet
|
4
|
+
# Comparison helpers, eg. or, and, equal, not equal, less than, greater than etc.
|
5
|
+
module Comparison
|
6
|
+
# Lt: Return true if left hand side LESS THAN right hand side
|
7
|
+
class Lt < Cmdlet::BaseCmdlet
|
8
|
+
#
|
9
|
+
# @param [Object] lhs - lhs - left hand side value
|
10
|
+
# @param [Object] rhs - rhs - right hand side value
|
11
|
+
# @return [String] truthy value if left hand side LESS THAN right hand side
|
12
|
+
def call(lhs, rhs)
|
13
|
+
lhs < rhs
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Cmdlet
|
4
|
+
# Comparison helpers, eg. or, and, equal, not equal, less than, greater than etc.
|
5
|
+
module Comparison
|
6
|
+
# Lte: Return true if left hand side LESS THAN or EQUAL TO right hand side
|
7
|
+
class Lte < Cmdlet::BaseCmdlet
|
8
|
+
#
|
9
|
+
# @param [Object] lhs - lhs - left hand side value
|
10
|
+
# @param [Object] rhs - rhs - right hand side value
|
11
|
+
# @return [String] truthy value if left hand side LESS THAN or EQUAL TO right hand side
|
12
|
+
def call(lhs, rhs)
|
13
|
+
lhs <= rhs
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Cmdlet
|
4
|
+
# Comparison helpers, eg. or, and, equal, not equal, less than, greater than etc.
|
5
|
+
module Comparison
|
6
|
+
# Ne: Return true if left hand side is NOT equal to right hand side
|
7
|
+
class Ne < Cmdlet::BaseCmdlet
|
8
|
+
#
|
9
|
+
# @param [Object] lhs - lhs - left hand side value
|
10
|
+
# @param [Object] rhs - rhs - right hand side value
|
11
|
+
# @return [String] truthy value if left hand side is NOT equal to right hand side
|
12
|
+
def call(lhs, rhs)
|
13
|
+
lhs = lhs.to_s if lhs.is_a?(Symbol)
|
14
|
+
rhs = rhs.to_s if rhs.is_a?(Symbol)
|
15
|
+
|
16
|
+
lhs != rhs
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Cmdlet
|
4
|
+
# Comparison helpers, eg. or, and, equal, not equal, less than, greater than etc.
|
5
|
+
module Comparison
|
6
|
+
# Or: Return true if any value is truthy.
|
7
|
+
class Or < Cmdlet::BaseCmdlet
|
8
|
+
#
|
9
|
+
# @param [Object] values - list of values (via *splat) to be checked via AND condition
|
10
|
+
# @return [String] return true when first value is truthy
|
11
|
+
def call(*values)
|
12
|
+
values.any? { |value| value }
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
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
|
+
# 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
|
data/lib/cmdlet/version.rb
CHANGED
data/lib/cmdlet.rb
CHANGED
@@ -2,10 +2,15 @@
|
|
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'
|
9
|
+
require_relative 'cmdlet/base_cmdlet'
|
7
10
|
require_relative 'cmdlet/string_tokenizer'
|
8
11
|
|
12
|
+
require_relative 'cmdlet/_'
|
13
|
+
|
9
14
|
module Cmdlet
|
10
15
|
# raise Cmdlet::Error, 'Sample message'
|
11
16
|
Error = Class.new(StandardError)
|
data/package-lock.json
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
{
|
2
2
|
"name": "cmdlet",
|
3
|
-
"version": "0.
|
3
|
+
"version": "0.2.1",
|
4
4
|
"lockfileVersion": 2,
|
5
5
|
"requires": true,
|
6
6
|
"packages": {
|
7
7
|
"": {
|
8
8
|
"name": "cmdlet",
|
9
|
-
"version": "0.
|
9
|
+
"version": "0.2.1",
|
10
10
|
"devDependencies": {
|
11
11
|
"@klueless-js/semantic-release-rubygem": "github:klueless-js/semantic-release-rubygem",
|
12
12
|
"@semantic-release/changelog": "^6.0.1",
|