cmdlet 0.0.4 → 0.0.7
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/all_commands.rb +5 -0
- data/.builders/.templates/command.rb +26 -0
- data/.builders/.templates/command_spec.rb +22 -0
- data/.builders/_.rb +5 -1
- data/.builders/boot.rb +4 -3
- data/.builders/data/categories.json +36 -0
- data/.builders/director/category_director.rb +25 -0
- data/.builders/director/cmdlet_builder.rb +74 -0
- data/.builders/director/cmdlet_child.rb +67 -0
- data/.builders/director/cmdlet_director.rb +36 -0
- data/.builders/documents/categories.rb +1 -1
- data/.builders/documents/cmdlets.rb +30 -0
- data/.builders/documents/commands.rb +221 -26
- data/.builders/generators/20-commands.rb +54 -0
- data/.builders/generators/25-categories.rb +20 -0
- data/CHANGELOG.md +21 -0
- data/lib/cmdlet/all_commands.rb +3 -0
- data/lib/cmdlet/array/join.rb +24 -0
- data/lib/cmdlet/configuration.rb +1 -1
- data/lib/cmdlet/string_tokenizer.rb +41 -0
- data/lib/cmdlet/version.rb +1 -1
- data/lib/cmdlet.rb +1 -0
- data/package-lock.json +2 -2
- data/package.json +1 -1
- metadata +34 -4
- data/.builders/documents/_.rb +0 -4
- data/.builders/documents/functions.rb +0 -226
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 49865609277b82bf27cc7275b38f0830109e2228b8ab3629ca1774d07b85f834
|
4
|
+
data.tar.gz: 7d6c2c92910fc466f8f0d3e04ebb4356dfb070c17e553a3e573c60e946648032
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d7bd4e1e6364146d104a96bd66425df76f3bd164b350f1b3328f046cc8c8e2b6f2d65eec9dacd18c7ce510e064846f10b0ba2a49315089f6ff0235e494b34387
|
7
|
+
data.tar.gz: e0ddc16a51d5c16957ac2241098de2f1a7a0de777f59621d8398da8e61172ae07c9ea796971e48ce024a646eee0c6b29cd1fe93fde4c6840c0d41b497c63da14
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# Funcky Functions
|
2
|
+
|
3
|
+
> Funcky provides a set of functions (wrapped in the command pattern) that perform simple actions
|
4
|
+
|
5
|
+
## List of categories
|
6
|
+
|
7
|
+
| Name | Description |
|
8
|
+
|-|-|
|
9
|
+
{{#each categories}}
|
10
|
+
| {{titleize name}} | {{description}} |
|
11
|
+
{{/each}}
|
12
|
+
|
13
|
+
## List of functions
|
14
|
+
|
15
|
+
| Category | Name | Alias | Description |
|
16
|
+
|-|-|-|-|
|
17
|
+
{{#each functions}}
|
18
|
+
| {{titleize category}} | `{{name}}` | {{#each alias}}{{surround . '`' '` '}}{{/each}} | {{description}} |
|
19
|
+
{{/each}}
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# reference: https://github.com/rails/rails/blob/master/activesupport/lib/active_support/inflector/methods.rb
|
4
|
+
|
5
|
+
module Cmdlet
|
6
|
+
# {{cmdlet.category_description}}
|
7
|
+
module {{camel cmdlet.category}}
|
8
|
+
# {{camel cmdlet.name}}: {{cmdlet.command_description}}
|
9
|
+
class {{camel cmdlet.name}} < Funcky::BaseFunction
|
10
|
+
{{#each cmdlet.usecases}}
|
11
|
+
# @example
|
12
|
+
#
|
13
|
+
# puts {{camel ./function}}.new.parse({{{nice_inputs}}})
|
14
|
+
#
|
15
|
+
# {{expected_output}}
|
16
|
+
#
|
17
|
+
{{/each}}
|
18
|
+
#
|
19
|
+
# @param [String|Int] value - numeric value
|
20
|
+
# @return [String] ordinal suffix that would be required for a number
|
21
|
+
def parse(value)
|
22
|
+
{{{cmdlet.ruby}}}
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# {{camel command.name}}: {{command.function_description}}
|
4
|
+
RSpec.describe Funcky::{{camel command.category}}::{{camel command.name}} do
|
5
|
+
let(:instance) { described_class.new }
|
6
|
+
|
7
|
+
describe 'initialize' do
|
8
|
+
subject { instance }
|
9
|
+
|
10
|
+
it { is_expected.not_to be_nil }
|
11
|
+
end
|
12
|
+
|
13
|
+
describe '#parse' do
|
14
|
+
subject { instance.parse(value) }
|
15
|
+
|
16
|
+
let(:value) { nil }
|
17
|
+
|
18
|
+
context 'safely handle nil' do
|
19
|
+
it { is_expected.to eq('') }
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/.builders/_.rb
CHANGED
data/.builders/boot.rb
CHANGED
@@ -49,10 +49,10 @@ KConfig.configure(CONFIG_KEY) do |config|
|
|
49
49
|
config.template_folders.add(:template , File.expand_path('.templates', Dir.pwd))
|
50
50
|
|
51
51
|
config.target_folders.add(:app , base_folder)
|
52
|
-
config.target_folders.add(:lib , :app, 'lib/
|
53
|
-
config.target_folders.add(:spec , :app, 'spec/
|
52
|
+
config.target_folders.add(:lib , :app, 'lib/cmdlet')
|
53
|
+
config.target_folders.add(:spec , :app, 'spec/cmdlet')
|
54
54
|
config.target_folders.add(:builder , builder_folder)
|
55
|
-
|
55
|
+
config.target_folders.add(:builder_data , :builder, 'data')
|
56
56
|
end
|
57
57
|
|
58
58
|
KConfig.configuration(CONFIG_KEY).debug
|
@@ -62,6 +62,7 @@ resource_manager = area.resource_manager
|
|
62
62
|
resource_manager
|
63
63
|
.fileset
|
64
64
|
.glob('*.rb', exclude: ['boot.rb'])
|
65
|
+
.glob('documents/**/*.rb')
|
65
66
|
.glob('generators/**/*.rb')
|
66
67
|
resource_manager.add_resources
|
67
68
|
|
@@ -0,0 +1,36 @@
|
|
1
|
+
{
|
2
|
+
"categories": [
|
3
|
+
{
|
4
|
+
"name": "case",
|
5
|
+
"description": "Tokenize and apply case and/or separator"
|
6
|
+
},
|
7
|
+
{
|
8
|
+
"name": "comparison",
|
9
|
+
"description": "Comparison helpers, eg. or, and, equal, not equal, less than, greater than etc."
|
10
|
+
},
|
11
|
+
{
|
12
|
+
"name": "inflection",
|
13
|
+
"description": "Inflection handling routines, eg. pluralize, singular, ordinalize"
|
14
|
+
},
|
15
|
+
{
|
16
|
+
"name": "string",
|
17
|
+
"description": "String handling helpers"
|
18
|
+
},
|
19
|
+
{
|
20
|
+
"name": "a_array",
|
21
|
+
"description": "Array handling routines, eg. join, join_prefix, join_post"
|
22
|
+
},
|
23
|
+
{
|
24
|
+
"name": "a_transform",
|
25
|
+
"description": "Tokenize and apply case and/or separator"
|
26
|
+
},
|
27
|
+
{
|
28
|
+
"name": "a_comparison",
|
29
|
+
"description": "Comparison helpers, eg. or, and, equal, not equal, less than, greater than etc."
|
30
|
+
},
|
31
|
+
{
|
32
|
+
"name": "a_inflection",
|
33
|
+
"description": "Inflection handling routines, eg. pluralize, singular, ordinalize"
|
34
|
+
}
|
35
|
+
]
|
36
|
+
}
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class CategoryDirector < KDirector::Directors::BaseDirector
|
4
|
+
def category(name, description)
|
5
|
+
value = {
|
6
|
+
name: name,
|
7
|
+
description: description
|
8
|
+
}
|
9
|
+
|
10
|
+
builder.add(:categories, value: value)
|
11
|
+
|
12
|
+
self
|
13
|
+
end
|
14
|
+
|
15
|
+
def category_file
|
16
|
+
k_builder.target_folders.join(:builder_data, 'categories.json')
|
17
|
+
end
|
18
|
+
|
19
|
+
def save_categories
|
20
|
+
cd(:builder_data)
|
21
|
+
add('categories.json', content: builder.to_json)
|
22
|
+
|
23
|
+
self
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class CmdletBuilder < KDirector::Builders::ActionsBuilder
|
4
|
+
attr_reader :current_helper
|
5
|
+
# attr_accessor :actions
|
6
|
+
# attr_accessor :last_action
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
super
|
10
|
+
|
11
|
+
dom[:helpers] = []
|
12
|
+
dom[:categories] = []
|
13
|
+
# @actions = []
|
14
|
+
# @last_action = {}
|
15
|
+
end
|
16
|
+
|
17
|
+
def category(name, description)
|
18
|
+
dom[:categories] << {
|
19
|
+
name: name,
|
20
|
+
description: description,
|
21
|
+
}
|
22
|
+
end
|
23
|
+
|
24
|
+
def helpers
|
25
|
+
dom[:helpers]
|
26
|
+
end
|
27
|
+
|
28
|
+
def add_helper
|
29
|
+
@current_helper = new_helper
|
30
|
+
dom[:helpers] << current_helper
|
31
|
+
end
|
32
|
+
|
33
|
+
def helper_setting(name, value)
|
34
|
+
@current_helper[name] = value
|
35
|
+
end
|
36
|
+
|
37
|
+
def add_helper_parameter(name, description, splat: false)
|
38
|
+
parameter = {
|
39
|
+
name: name,
|
40
|
+
description: description,
|
41
|
+
splat: splat
|
42
|
+
}
|
43
|
+
|
44
|
+
@current_helper[:parameters] << parameter
|
45
|
+
end
|
46
|
+
|
47
|
+
def add_helper_example(value)
|
48
|
+
lines = value.split("\n")
|
49
|
+
value = lines.map { |line| " # #{line.strip}" }.join("\n")
|
50
|
+
|
51
|
+
@current_helper[:examples] << value
|
52
|
+
end
|
53
|
+
|
54
|
+
|
55
|
+
private
|
56
|
+
|
57
|
+
def new_helper
|
58
|
+
{
|
59
|
+
name: nil,
|
60
|
+
description: nil,
|
61
|
+
result: nil,
|
62
|
+
category: nil,
|
63
|
+
category_description: nil,
|
64
|
+
base_class_require: nil,
|
65
|
+
base_class: nil,
|
66
|
+
example_input_value: nil,
|
67
|
+
example_output_value: nil,
|
68
|
+
test_input_value: nil,
|
69
|
+
test_output_value: nil,
|
70
|
+
parameters: [],
|
71
|
+
examples: []
|
72
|
+
}
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class HandlebarsHelperChild < KDirector::Directors::ChildDirector
|
4
|
+
def initialize(parent, **opts)
|
5
|
+
super(parent, **opts)
|
6
|
+
|
7
|
+
builder.add_helper
|
8
|
+
|
9
|
+
# defaults = {
|
10
|
+
# repo_name: opts[:repo_name], # || parent.builder.dom&[:github]&[:repo_name]
|
11
|
+
# username: opts[:username] || default_github_username, # || parent.builder.dom&[:github]&[:username]
|
12
|
+
# organization: opts[:organization] # || parent.builder.dom&[:github]&[:organization]
|
13
|
+
# }
|
14
|
+
end
|
15
|
+
|
16
|
+
def name(value)
|
17
|
+
builder.helper_setting(:name, value)
|
18
|
+
end
|
19
|
+
|
20
|
+
def description(value)
|
21
|
+
builder.helper_setting(:description, value)
|
22
|
+
end
|
23
|
+
|
24
|
+
def result(value)
|
25
|
+
builder.helper_setting(:result, value)
|
26
|
+
end
|
27
|
+
|
28
|
+
def category(value)
|
29
|
+
builder.helper_setting(:category, value)
|
30
|
+
end
|
31
|
+
|
32
|
+
def category_description(value)
|
33
|
+
builder.helper_setting(:category_description, value)
|
34
|
+
end
|
35
|
+
|
36
|
+
# def base_class_require(value)
|
37
|
+
# builder.helper_setting(:base_class_require, value)
|
38
|
+
# end
|
39
|
+
|
40
|
+
# def base_class(value)
|
41
|
+
# builder.helper_setting(:base_class, value)
|
42
|
+
# end
|
43
|
+
|
44
|
+
# def example_input_value(value)
|
45
|
+
# builder.helper_setting(:example_input_value, value)
|
46
|
+
# end
|
47
|
+
|
48
|
+
# def example_output_value(value)
|
49
|
+
# builder.helper_setting(:example_output_value, value)
|
50
|
+
# end
|
51
|
+
|
52
|
+
# def test_input_value(value)
|
53
|
+
# builder.helper_setting(:test_input_value, value)
|
54
|
+
# end
|
55
|
+
|
56
|
+
# def test_output_value(value)
|
57
|
+
# builder.helper_setting(:test_output_value, value)
|
58
|
+
# end
|
59
|
+
|
60
|
+
def parameter(name, description, splat: false)
|
61
|
+
builder.add_helper_parameter(name, description, splat: splat)
|
62
|
+
end
|
63
|
+
|
64
|
+
def example(value)
|
65
|
+
builder.add_helper_example(value)
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class CmdletDirector < KDirector::Directors::BaseDirector
|
4
|
+
default_builder_type(CmdletBuilder)
|
5
|
+
|
6
|
+
def category(name, description)
|
7
|
+
builder.category(name, description)
|
8
|
+
|
9
|
+
self
|
10
|
+
end
|
11
|
+
|
12
|
+
def helper(**opts, &block)
|
13
|
+
helper = CmdletChild.new(self, **opts)
|
14
|
+
helper.instance_eval(&block) if block_given?
|
15
|
+
|
16
|
+
self
|
17
|
+
end
|
18
|
+
|
19
|
+
def build_helpers
|
20
|
+
builder.helpers.each do |helper|
|
21
|
+
cd(:lib)
|
22
|
+
add("helpers/#{helper[:category]}/#{helper[:name]}.rb", template_file: 'helper.rb', helper: helper)
|
23
|
+
|
24
|
+
cd(:spec)
|
25
|
+
add("helpers/#{helper[:category]}/#{helper[:name]}_spec.rb", template_file: 'helper_spec.rb', helper: helper)
|
26
|
+
end
|
27
|
+
|
28
|
+
self
|
29
|
+
end
|
30
|
+
|
31
|
+
def save_categories
|
32
|
+
cd(:builder_data)
|
33
|
+
add('categories.json', content: JSON.pretty_generate(builder.categories.map(&:to_h)))
|
34
|
+
play_actions
|
35
|
+
end
|
36
|
+
end
|
@@ -11,7 +11,7 @@ def categories
|
|
11
11
|
row :inflection , "Inflection handling routines, eg. pluralize, singular, ordinalize"
|
12
12
|
row :string , "String handling helpers"
|
13
13
|
|
14
|
-
row :
|
14
|
+
row :array , "Array handling routines, eg. join, join_prefix, join_post"
|
15
15
|
row :a_transform , "Tokenize and apply case and/or separator"
|
16
16
|
row :a_comparison , "Comparison helpers, eg. or, and, equal, not equal, less than, greater than etc."
|
17
17
|
row :a_inflection , "Inflection handling routines, eg. pluralize, singular, ordinalize"
|
@@ -0,0 +1,30 @@
|
|
1
|
+
def cmdlets
|
2
|
+
commands.map do |command|
|
3
|
+
category = categories.find { |c| c.name == command.category }
|
4
|
+
|
5
|
+
log.error("Category '#{command.category}' not found") unless category
|
6
|
+
|
7
|
+
OpenStruct.new(
|
8
|
+
category: command.category,
|
9
|
+
name: command.name,
|
10
|
+
category_description: category.description,
|
11
|
+
command_description: command.description,
|
12
|
+
ruby: command.ruby,
|
13
|
+
usecases: use_cases
|
14
|
+
.select { |uc| uc.category == command.category && uc.command == command.name }
|
15
|
+
.map { |uc|
|
16
|
+
OpenStruct.new({
|
17
|
+
category: uc.category,
|
18
|
+
command: uc.command,
|
19
|
+
inputs: uc.inputs,
|
20
|
+
nice_inputs: nice_inputs(uc.inputs),
|
21
|
+
expected_output: uc.expected_output
|
22
|
+
})
|
23
|
+
}
|
24
|
+
)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def nice_inputs(values)
|
29
|
+
values.map { |value| value.is_a?(String) ? "'#{value}'" : value }.join(', ')
|
30
|
+
end
|
@@ -1,31 +1,226 @@
|
|
1
1
|
def commands
|
2
|
-
|
3
|
-
|
2
|
+
return @commands unless @commands.nil?
|
3
|
+
|
4
|
+
result = KDoc.model :document do
|
5
|
+
table :rows do
|
6
|
+
fields :category, :name, :alias, :description, :ruby # , f(name: :params, default: [:value])
|
7
|
+
|
8
|
+
# context 'when array of string' do
|
9
|
+
# let(:value) { %w[the quick fox] }
|
10
|
+
|
11
|
+
# it { is_expected.to eq('the,quick,fox') }
|
12
|
+
# end
|
13
|
+
|
14
|
+
# context 'when array of numbers' do
|
15
|
+
# let(:value) { [1, 2, 3] }
|
16
|
+
|
17
|
+
# it { is_expected.to eq('1,2,3') }
|
18
|
+
# end
|
19
|
+
|
20
|
+
# context 'when array of symbol' do
|
21
|
+
# let(:value) { %i[the quick fox] }
|
22
|
+
|
23
|
+
# it { is_expected.to eq('the,quick,fox') }
|
24
|
+
# end
|
25
|
+
|
26
|
+
row :array , :join , [] , "join an array of values with separator as a string", <<-'RUBY'
|
27
|
+
return '' if value.nil? || !value.is_a?(Array)
|
28
|
+
values = value.reject(&:blank?)
|
29
|
+
return '' if value.length.zero?
|
30
|
+
|
31
|
+
separator = ','
|
32
|
+
values.join(separator)
|
33
|
+
RUBY
|
34
|
+
|
35
|
+
# row :array , :join_pre , [] , "join an array of values with separator as a string and using the separator at the beginning of string", <<-'RUBY'
|
36
|
+
# return '' if value.nil? || !value.is_a?(Array)
|
37
|
+
# values = value.reject(&:blank?)
|
38
|
+
# return '' if value.length.zero?
|
39
|
+
|
40
|
+
# separator = ','
|
41
|
+
# "#{separator}#{value.join(separator)}"
|
42
|
+
# RUBY
|
43
|
+
|
44
|
+
# row :array , :join_post , [] , "join an array of values with separator as a string and using the separator at the end of string", <<-'RUBY'
|
45
|
+
# return '' if value.nil? || !value.is_a?(Array)
|
46
|
+
# values = value.reject(&:blank?)
|
47
|
+
# return '' if value.length.zero?
|
48
|
+
|
49
|
+
# separator = ','
|
50
|
+
# "#{value.join(separator)}#{separator}"
|
51
|
+
# RUBY
|
52
|
+
|
53
|
+
# row :a_transform , :backslash , [:back_slash] , "convert to back slash notation", <<-'RUBY'
|
54
|
+
# tokenizer.parse(value, preserve_case: true, separator: '\\')
|
55
|
+
# RUBY
|
56
|
+
|
57
|
+
# row :a_transform , :camel , [:upper_camel, :pascal] , "convert to camel notation", <<-'RUBY'
|
58
|
+
# tokenizer.parse(value).underscore.camelize
|
59
|
+
# RUBY
|
60
|
+
|
61
|
+
# row :a_transform , :constant , [:constantize] , "", <<-'RUBY'
|
62
|
+
# tokenizer.parse(value, separator: '_').upcase
|
63
|
+
# RUBY
|
64
|
+
|
65
|
+
# row :a_transform , :dash , [:dasherize] , "convert to dash notation", <<-'RUBY'
|
66
|
+
# tokenizer.parse(value)
|
67
|
+
# RUBY
|
68
|
+
|
69
|
+
# row :a_transform , :dot , [:dotirize] , "", <<-'RUBY'
|
70
|
+
# tokenizer.parse(value, separator: '.')
|
71
|
+
# RUBY
|
72
|
+
|
73
|
+
# row :a_transform , :double_colon , [] , "", <<-'RUBY'
|
74
|
+
# tokenizer.parse(value, preserve_case: true, separator: '::')
|
75
|
+
# RUBY
|
76
|
+
|
77
|
+
# row :a_transform , :lower , [:lowercase, :downcase] , "", <<-'RUBY'
|
78
|
+
# return '' if value.nil?
|
79
|
+
|
80
|
+
# value.downcase
|
81
|
+
# RUBY
|
82
|
+
|
83
|
+
# # row :a_transform , :format_as , [] , "", <<-'RUBY'
|
84
|
+
|
85
|
+
# # RUBY
|
86
|
+
|
87
|
+
# row :a_transform , :proper , [] , "Proper case capitalizes the first letter of ALL words in a string", <<-'RUBY'
|
88
|
+
# tokenizer.parse(value,
|
89
|
+
# separator: ' ',
|
90
|
+
# preserve_case: true,
|
91
|
+
# compress_prefix_numerals: false,
|
92
|
+
# compress_suffix_numerals: false)
|
93
|
+
# .titleize
|
94
|
+
# RUBY
|
95
|
+
|
96
|
+
# row :a_transform , :sentence , [:human, :humanize] , "Upper case for first letter only. Numbers will maintain their spacing", <<-'RUBY'
|
97
|
+
# tokenizer.parse(value,
|
98
|
+
# separator: ' ',
|
99
|
+
# preserve_case: true,
|
100
|
+
# compress_prefix_numerals: false,
|
101
|
+
# compress_suffix_numerals: false)
|
102
|
+
# .humanize
|
103
|
+
# RUBY
|
104
|
+
|
105
|
+
# row :a_transform , :lamel , [:lower_camel] , "", <<-'RUBY'
|
106
|
+
# tokenizer.parse(value, separator: '_').camelize(:lower)
|
107
|
+
# RUBY
|
108
|
+
|
109
|
+
# row :a_transform , :slash , [:forwardslash, :forward_slash] , "", <<-'RUBY'
|
110
|
+
# tokenizer.parse(value, preserve_case: true, separator: '/')
|
111
|
+
# RUBY
|
112
|
+
|
113
|
+
# row :a_transform , :snake , [:snake] , "", <<-'RUBY'
|
114
|
+
# tokenizer.parse(value, separator: '_', forced_separator: true)
|
115
|
+
# RUBY
|
116
|
+
|
117
|
+
# row :a_transform , :title , [:titleize] , "", <<-'RUBY'
|
118
|
+
# tokenizer.parse(value,
|
119
|
+
# separator: ' ',
|
120
|
+
# preserve_case: true,
|
121
|
+
# compress_prefix_numerals: false,
|
122
|
+
# compress_suffix_numerals: false)
|
123
|
+
# .titleize
|
124
|
+
# RUBY
|
125
|
+
|
126
|
+
# row :a_transform , :upper , [:upper_case, :upcase] , "", <<-'RUBY'
|
127
|
+
# return '' if value.nil?
|
128
|
+
|
129
|
+
# value.upcase
|
130
|
+
# RUBY
|
4
131
|
|
5
|
-
|
6
|
-
log.error("Category '#{function.category}' not found") unless category
|
7
132
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
133
|
+
# row :a_comparison , :and , [:all] , "", <<-'RUBY'
|
134
|
+
# values.all? { |value| value }
|
135
|
+
# RUBY
|
136
|
+
|
137
|
+
# # DEFAULT does not make sense in comparison
|
138
|
+
# row :a_comparison , :default , [:fallback] , "", <<-'RUBY'
|
139
|
+
# default_value = values[-1]
|
140
|
+
|
141
|
+
# find_value = values[0..-2].find { |value| !value.nil? }
|
142
|
+
|
143
|
+
# find_value || default_value
|
144
|
+
# RUBY
|
145
|
+
|
146
|
+
# row :a_comparison , :eq , [:equal] , "", <<-'RUBY'
|
147
|
+
# lhs = lhs.to_s if lhs.is_a?(Symbol)
|
148
|
+
# rhs = rhs.to_s if rhs.is_a?(Symbol)
|
149
|
+
|
150
|
+
# lhs == rhs
|
151
|
+
# RUBY
|
152
|
+
|
153
|
+
# row :a_comparison , :gt , [] , "", <<-'RUBY'
|
154
|
+
# lhs > rhs
|
155
|
+
# RUBY
|
156
|
+
|
157
|
+
# row :a_comparison , :gte , [] , "", <<-'RUBY'
|
158
|
+
# lhs >= rhs
|
159
|
+
# RUBY
|
160
|
+
|
161
|
+
# row :a_comparison , :lt , [:less_than] , "# Lt: (less than) Block helper that renders a block if `a` is **less than** `b`. If an inverse block is specified it will be rendered when falsy.", <<-'RUBY'
|
162
|
+
# lhs < rhs
|
163
|
+
# RUBY
|
164
|
+
|
165
|
+
# row :a_comparison , :lte , [:less_than_or_equal_to] , "# Lte: (less than or equal to) Block helper that renders a block if `a` is **less than or equal to** `b`. If an inverse block is specified it will be rendered when falsy.", <<-'RUBY'
|
166
|
+
# lhs <= rhs
|
167
|
+
# RUBY
|
168
|
+
|
169
|
+
# row :a_comparison , :ne , [:not_equal] , "# Ne: (not equal) Block helper that renders a block if `a` is **not equal to** `b`. If an inverse block is specified it will be rendered when falsy.", <<-'RUBY'
|
170
|
+
# lhs = lhs.to_s if lhs.is_a?(Symbol)
|
171
|
+
# rhs = rhs.to_s if rhs.is_a?(Symbol)
|
172
|
+
|
173
|
+
# lhs != rhs
|
174
|
+
# RUBY
|
175
|
+
|
176
|
+
# row :a_comparison , :or , [:any] , "", <<-'RUBY'
|
177
|
+
# values.any? { |value| value }
|
178
|
+
# RUBY
|
179
|
+
|
180
|
+
|
181
|
+
|
182
|
+
# row :a_inflection , :ordinal , [] , "The suffix that should be added to a number to denote the position in an ordered sequence such as 1st, 2nd, 3rd, 4th", <<-RUBY
|
183
|
+
# return '' if value.nil?
|
184
|
+
|
185
|
+
# value = value.to_i if value.is_a? String
|
186
|
+
|
187
|
+
# value.ordinal
|
188
|
+
# RUBY
|
189
|
+
|
190
|
+
# row :a_inflection , :ordinalize , [] , "Turns a number into an ordinal string used to denote the position in an ordered sequence such as 1st, 2nd, 3rd, 4th.", <<-RUBY
|
191
|
+
# return '' if value.nil?
|
192
|
+
|
193
|
+
# value = value.to_i if value.is_a? String
|
194
|
+
|
195
|
+
# value.ordinalize
|
196
|
+
# RUBY
|
197
|
+
|
198
|
+
# row :a_inflection , :pluralize , [] , "Returns the plural form of the word in the string", <<-RUBY
|
199
|
+
# return '' if value.nil?
|
200
|
+
|
201
|
+
# value = value.to_s if value.is_a?(Symbol)
|
202
|
+
|
203
|
+
# value.pluralize
|
204
|
+
# RUBY
|
205
|
+
|
206
|
+
# row :a_inflection , :pluralize_by_number , [] , "Uses both a word and number to decide if the plural or singular form should be used.", <<-'RUBY'
|
207
|
+
# return '' if value.nil?
|
208
|
+
|
209
|
+
# count = count.to_i if count.is_a? String
|
210
|
+
# format = :word if format.nil?
|
211
|
+
|
212
|
+
# case format.to_sym
|
213
|
+
# when :number_word, :number_and_word
|
214
|
+
# "#{count} #{value.pluralize(count)}"
|
215
|
+
# else # aka :word
|
216
|
+
# value.pluralize(count)
|
217
|
+
# end
|
218
|
+
# RUBY
|
219
|
+
|
220
|
+
# row :a_inflection , :singularize , [] , ""
|
221
|
+
end
|
26
222
|
end
|
223
|
+
|
224
|
+
@commands = result.raw_data_struct.rows
|
27
225
|
end
|
28
|
-
|
29
|
-
def nice_inputs(values)
|
30
|
-
values.map { |value| value.is_a?(String) ? "'#{value}'" : value }.join(', ')
|
31
|
-
end
|
226
|
+
@commands = nil
|
@@ -0,0 +1,54 @@
|
|
1
|
+
KManager.action :commands do
|
2
|
+
action do
|
3
|
+
|
4
|
+
puts commands.first.function_description
|
5
|
+
# Ruby Gem Bootstrap
|
6
|
+
director = KDirector::Dsls::BasicDsl
|
7
|
+
.init(k_builder,
|
8
|
+
template_base_folder: '',
|
9
|
+
on_exist: :skip, # %i[skip write compare]
|
10
|
+
on_action: :queue # %i[queue execute]
|
11
|
+
)
|
12
|
+
.blueprint(
|
13
|
+
active: true,
|
14
|
+
name: :build_commands,
|
15
|
+
description: 'Build Commandlets',
|
16
|
+
on_exist: :write) do
|
17
|
+
|
18
|
+
cd(:lib)
|
19
|
+
|
20
|
+
# builder
|
21
|
+
# .add_file('FUNCTIONS.md',
|
22
|
+
# template_file: 'FUNCTIONS.md',
|
23
|
+
# categories: categories.sort_by { |r| r.name },
|
24
|
+
# functions: functions.sort_by { |r| [r.category, r.name] },
|
25
|
+
# on_exist: :write)
|
26
|
+
|
27
|
+
add('all_commands.rb',
|
28
|
+
template_file: 'all_commands.rb',
|
29
|
+
commands: commands.sort_by { |r| [r.category, r.name] },
|
30
|
+
on_exist: :write)
|
31
|
+
|
32
|
+
cmdlets.each do |cmdlet|
|
33
|
+
|
34
|
+
add("#{cmdlet.category}/#{cmdlet.name}.rb",
|
35
|
+
cmdlet: cmdlet,
|
36
|
+
template_file: 'command.rb',
|
37
|
+
on_exist: :write)
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
director.play_actions
|
43
|
+
# director.builder.logit
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
KManager.opts.app_name = 'commands'
|
48
|
+
KManager.opts.sleep = 2
|
49
|
+
KManager.opts.reboot_on_kill = 0
|
50
|
+
KManager.opts.reboot_sleep = 4
|
51
|
+
KManager.opts.exception_style = :short
|
52
|
+
KManager.opts.show.time_taken = true
|
53
|
+
KManager.opts.show.finished = true
|
54
|
+
KManager.opts.show.finished_message = 'FINISHED :)'
|
@@ -0,0 +1,20 @@
|
|
1
|
+
KManager.action :categories do
|
2
|
+
action do
|
3
|
+
|
4
|
+
CategoryDirector
|
5
|
+
.init(k_builder,
|
6
|
+
on_exist: :write, # %i[skip write compare]
|
7
|
+
on_action: :execute # %i[queue execute]
|
8
|
+
)
|
9
|
+
.category(:case , "Tokenize and apply case and/or separator")
|
10
|
+
.category(:comparison , "Comparison helpers, eg. or, and, equal, not equal, less than, greater than etc.")
|
11
|
+
.category(:inflection , "Inflection handling routines, eg. pluralize, singular, ordinalize")
|
12
|
+
.category(:string , "String handling helpers")
|
13
|
+
.category(:a_array , "Array handling routines, eg. join, join_prefix, join_post")
|
14
|
+
.category(:a_transform , "Tokenize and apply case and/or separator")
|
15
|
+
.category(:a_comparison , "Comparison helpers, eg. or, and, equal, not equal, less than, greater than etc.")
|
16
|
+
.category(:a_inflection , "Inflection handling routines, eg. pluralize, singular, ordinalize")
|
17
|
+
.save_categories
|
18
|
+
.category_file
|
19
|
+
end
|
20
|
+
end
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,24 @@
|
|
1
|
+
## [0.0.6](https://github.com/klueless-io/cmdlet/compare/v0.0.5...v0.0.6) (2022-07-08)
|
2
|
+
|
3
|
+
|
4
|
+
### Bug Fixes
|
5
|
+
|
6
|
+
* add tests for configuration ([59a764f](https://github.com/klueless-io/cmdlet/commit/59a764f99f84dbe1c5b1022e8fdc2386fcced92a))
|
7
|
+
|
8
|
+
## [0.0.5](https://github.com/klueless-io/cmdlet/compare/v0.0.4...v0.0.5) (2022-07-08)
|
9
|
+
|
10
|
+
|
11
|
+
### Bug Fixes
|
12
|
+
|
13
|
+
* add string tokenizer ([9d996ff](https://github.com/klueless-io/cmdlet/commit/9d996ff97545617b894d2f29c4500dc44df492b7))
|
14
|
+
|
15
|
+
## [0.0.4](https://github.com/klueless-io/cmdlet/compare/v0.0.3...v0.0.4) (2022-07-08)
|
16
|
+
|
17
|
+
|
18
|
+
### Bug Fixes
|
19
|
+
|
20
|
+
* add basic configuration ([d8ecbb1](https://github.com/klueless-io/cmdlet/commit/d8ecbb17f61600de3b3f5d8987cc132d6e5ba0b2))
|
21
|
+
|
1
22
|
## [0.0.3](https://github.com/klueless-io/cmdlet/compare/v0.0.2...v0.0.3) (2022-07-08)
|
2
23
|
|
3
24
|
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# reference: https://github.com/rails/rails/blob/master/activesupport/lib/active_support/inflector/methods.rb
|
4
|
+
|
5
|
+
module Cmdlet
|
6
|
+
# Array handling routines, eg. join, join_prefix, join_post
|
7
|
+
module Array
|
8
|
+
# Join: join an array of values with separator as a string
|
9
|
+
class Join < Funcky::BaseFunction
|
10
|
+
#
|
11
|
+
# @param [String|Int] value - numeric value
|
12
|
+
# @return [String] ordinal suffix that would be required for a number
|
13
|
+
def parse(value)
|
14
|
+
return '' if value.nil? || !value.is_a?(Array)
|
15
|
+
|
16
|
+
values = value.reject(&:blank?)
|
17
|
+
return '' if value.length.zero?
|
18
|
+
|
19
|
+
separator = ','
|
20
|
+
values.join(separator)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/lib/cmdlet/configuration.rb
CHANGED
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'active_support/core_ext/string'
|
4
|
+
|
5
|
+
module Cmdlet
|
6
|
+
# String tokenizer will clean up a string so that all sorts of formatted strings can be
|
7
|
+
# represented in a consistent fashion
|
8
|
+
class StringTokenizer
|
9
|
+
# Tokenize string
|
10
|
+
# rubocop:disable Metrics/ParameterLists
|
11
|
+
def parse(value,
|
12
|
+
preserve_case: false,
|
13
|
+
compress_prefix_numerals: true,
|
14
|
+
compress_suffix_numerals: true,
|
15
|
+
separator: '-',
|
16
|
+
forced_separator: false)
|
17
|
+
return '' if value.nil?
|
18
|
+
|
19
|
+
# Insert space before any lowercaseUppercase
|
20
|
+
value = value.gsub(/(?<=[a-z])(?=[A-Z])/, ' ')
|
21
|
+
|
22
|
+
# make sure that any numbers followed by space and then some text has the white space removed
|
23
|
+
value = value.gsub(/^(\d*)(\s*)/, '\1') if compress_prefix_numerals
|
24
|
+
|
25
|
+
# Technique1: make sure that trailing space followed by number is compressed
|
26
|
+
# NOTE: named groups don't seem to work with \1, \2 etc.
|
27
|
+
# ex = /(?<space>[\s]*)(?<number>[\d]*)$/
|
28
|
+
# value =value.sub(ex) { |_| Regexp.last_match[:number] }
|
29
|
+
|
30
|
+
# Technique2: make sure that trailing space followed by number is compressed
|
31
|
+
value = value.gsub(/(\s*)(\d*)$/, '\2') if compress_suffix_numerals
|
32
|
+
|
33
|
+
value = value.parameterize(preserve_case: preserve_case, separator: separator) # (separator: ' ')
|
34
|
+
|
35
|
+
value = value.gsub(/[-_]/, separator) if forced_separator
|
36
|
+
|
37
|
+
value
|
38
|
+
end
|
39
|
+
# rubocop:enable Metrics/ParameterLists
|
40
|
+
end
|
41
|
+
end
|
data/lib/cmdlet/version.rb
CHANGED
data/lib/cmdlet.rb
CHANGED
data/package-lock.json
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
{
|
2
2
|
"name": "cmdlet",
|
3
|
-
"version": "0.0.
|
3
|
+
"version": "0.0.7",
|
4
4
|
"lockfileVersion": 2,
|
5
5
|
"requires": true,
|
6
6
|
"packages": {
|
7
7
|
"": {
|
8
8
|
"name": "cmdlet",
|
9
|
-
"version": "0.0.
|
9
|
+
"version": "0.0.7",
|
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
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cmdlet
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Cruwys
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-07-
|
11
|
+
date: 2022-07-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activesupport
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '6'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '6'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: k_config
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -32,15 +46,25 @@ executables: []
|
|
32
46
|
extensions: []
|
33
47
|
extra_rdoc_files: []
|
34
48
|
files:
|
49
|
+
- ".builders/.templates/FUNCTIONS.MD"
|
50
|
+
- ".builders/.templates/all_commands.rb"
|
51
|
+
- ".builders/.templates/command.rb"
|
52
|
+
- ".builders/.templates/command_spec.rb"
|
35
53
|
- ".builders/_.rb"
|
36
54
|
- ".builders/boot.rb"
|
37
|
-
- ".builders/
|
55
|
+
- ".builders/data/categories.json"
|
56
|
+
- ".builders/director/category_director.rb"
|
57
|
+
- ".builders/director/cmdlet_builder.rb"
|
58
|
+
- ".builders/director/cmdlet_child.rb"
|
59
|
+
- ".builders/director/cmdlet_director.rb"
|
38
60
|
- ".builders/documents/categories.rb"
|
61
|
+
- ".builders/documents/cmdlets.rb"
|
39
62
|
- ".builders/documents/commands.rb"
|
40
|
-
- ".builders/documents/functions.rb"
|
41
63
|
- ".builders/documents/use_cases.rb"
|
42
64
|
- ".builders/documents/x_functions.rb"
|
43
65
|
- ".builders/generators/01-bootstrap.rb"
|
66
|
+
- ".builders/generators/20-commands.rb"
|
67
|
+
- ".builders/generators/25-categories.rb"
|
44
68
|
- ".releaserc.json"
|
45
69
|
- ".rspec"
|
46
70
|
- ".rubocop.yml"
|
@@ -54,7 +78,10 @@ files:
|
|
54
78
|
- bin/console
|
55
79
|
- bin/setup
|
56
80
|
- lib/cmdlet.rb
|
81
|
+
- lib/cmdlet/all_commands.rb
|
82
|
+
- lib/cmdlet/array/join.rb
|
57
83
|
- lib/cmdlet/configuration.rb
|
84
|
+
- lib/cmdlet/string_tokenizer.rb
|
58
85
|
- lib/cmdlet/version.rb
|
59
86
|
- package-lock.json
|
60
87
|
- package.json
|
@@ -63,6 +90,9 @@ homepage: http://appydave.com/gems/cmdlet
|
|
63
90
|
licenses:
|
64
91
|
- MIT
|
65
92
|
metadata:
|
93
|
+
homepage_uri: http://appydave.com/gems/cmdlet
|
94
|
+
source_code_uri: https://github.com/klueless-io/cmdlet
|
95
|
+
changelog_uri: https://github.com/klueless-io/cmdlet/blob/main/CHANGELOG.md
|
66
96
|
rubygems_mfa_required: 'true'
|
67
97
|
post_install_message:
|
68
98
|
rdoc_options: []
|
data/.builders/documents/_.rb
DELETED
@@ -1,226 +0,0 @@
|
|
1
|
-
def functions
|
2
|
-
return @functions unless @functions.nil?
|
3
|
-
|
4
|
-
result = KDoc.model :document do
|
5
|
-
table :rows do
|
6
|
-
fields :category, :name, :alias, :description, :ruby # , f(name: :params, default: [:value])
|
7
|
-
|
8
|
-
# context 'when array of string' do
|
9
|
-
# let(:value) { %w[the quick fox] }
|
10
|
-
|
11
|
-
# it { is_expected.to eq('the,quick,fox') }
|
12
|
-
# end
|
13
|
-
|
14
|
-
# context 'when array of numbers' do
|
15
|
-
# let(:value) { [1, 2, 3] }
|
16
|
-
|
17
|
-
# it { is_expected.to eq('1,2,3') }
|
18
|
-
# end
|
19
|
-
|
20
|
-
# context 'when array of symbol' do
|
21
|
-
# let(:value) { %i[the quick fox] }
|
22
|
-
|
23
|
-
# it { is_expected.to eq('the,quick,fox') }
|
24
|
-
# end
|
25
|
-
|
26
|
-
row :a_array , :join , [] , "join an array of values with separator as a string", <<-'RUBY'
|
27
|
-
return '' if value.nil? || !value.is_a?(Array)
|
28
|
-
values = value.reject(&:blank?)
|
29
|
-
return '' if value.length.zero?
|
30
|
-
|
31
|
-
separator = ','
|
32
|
-
value.join(separator)
|
33
|
-
RUBY
|
34
|
-
|
35
|
-
row :a_array , :join_pre , [] , "join an array of values with separator as a string and using the separator at the beginning of string", <<-'RUBY'
|
36
|
-
return '' if value.nil? || !value.is_a?(Array)
|
37
|
-
values = value.reject(&:blank?)
|
38
|
-
return '' if value.length.zero?
|
39
|
-
|
40
|
-
separator = ','
|
41
|
-
"#{separator}#{value.join(separator)}"
|
42
|
-
RUBY
|
43
|
-
|
44
|
-
row :a_array , :join_post , [] , "join an array of values with separator as a string and using the separator at the end of string", <<-'RUBY'
|
45
|
-
return '' if value.nil? || !value.is_a?(Array)
|
46
|
-
values = value.reject(&:blank?)
|
47
|
-
return '' if value.length.zero?
|
48
|
-
|
49
|
-
separator = ','
|
50
|
-
"#{value.join(separator)}#{separator}"
|
51
|
-
RUBY
|
52
|
-
|
53
|
-
row :a_transform , :backslash , [:back_slash] , "convert to back slash notation", <<-'RUBY'
|
54
|
-
tokenizer.parse(value, preserve_case: true, separator: '\\')
|
55
|
-
RUBY
|
56
|
-
|
57
|
-
row :a_transform , :camel , [:upper_camel, :pascal] , "convert to camel notation", <<-'RUBY'
|
58
|
-
tokenizer.parse(value).underscore.camelize
|
59
|
-
RUBY
|
60
|
-
|
61
|
-
row :a_transform , :constant , [:constantize] , "", <<-'RUBY'
|
62
|
-
tokenizer.parse(value, separator: '_').upcase
|
63
|
-
RUBY
|
64
|
-
|
65
|
-
row :a_transform , :dash , [:dasherize] , "convert to dash notation", <<-'RUBY'
|
66
|
-
tokenizer.parse(value)
|
67
|
-
RUBY
|
68
|
-
|
69
|
-
row :a_transform , :dot , [:dotirize] , "", <<-'RUBY'
|
70
|
-
tokenizer.parse(value, separator: '.')
|
71
|
-
RUBY
|
72
|
-
|
73
|
-
row :a_transform , :double_colon , [] , "", <<-'RUBY'
|
74
|
-
tokenizer.parse(value, preserve_case: true, separator: '::')
|
75
|
-
RUBY
|
76
|
-
|
77
|
-
row :a_transform , :lower , [:lowercase, :downcase] , "", <<-'RUBY'
|
78
|
-
return '' if value.nil?
|
79
|
-
|
80
|
-
value.downcase
|
81
|
-
RUBY
|
82
|
-
|
83
|
-
# row :a_transform , :format_as , [] , "", <<-'RUBY'
|
84
|
-
|
85
|
-
# RUBY
|
86
|
-
|
87
|
-
row :a_transform , :proper , [] , "Proper case capitalizes the first letter of ALL words in a string", <<-'RUBY'
|
88
|
-
tokenizer.parse(value,
|
89
|
-
separator: ' ',
|
90
|
-
preserve_case: true,
|
91
|
-
compress_prefix_numerals: false,
|
92
|
-
compress_suffix_numerals: false)
|
93
|
-
.titleize
|
94
|
-
RUBY
|
95
|
-
|
96
|
-
row :a_transform , :sentence , [:human, :humanize] , "Upper case for first letter only. Numbers will maintain their spacing", <<-'RUBY'
|
97
|
-
tokenizer.parse(value,
|
98
|
-
separator: ' ',
|
99
|
-
preserve_case: true,
|
100
|
-
compress_prefix_numerals: false,
|
101
|
-
compress_suffix_numerals: false)
|
102
|
-
.humanize
|
103
|
-
RUBY
|
104
|
-
|
105
|
-
row :a_transform , :lamel , [:lower_camel] , "", <<-'RUBY'
|
106
|
-
tokenizer.parse(value, separator: '_').camelize(:lower)
|
107
|
-
RUBY
|
108
|
-
|
109
|
-
row :a_transform , :slash , [:forwardslash, :forward_slash] , "", <<-'RUBY'
|
110
|
-
tokenizer.parse(value, preserve_case: true, separator: '/')
|
111
|
-
RUBY
|
112
|
-
|
113
|
-
row :a_transform , :snake , [:snake] , "", <<-'RUBY'
|
114
|
-
tokenizer.parse(value, separator: '_', forced_separator: true)
|
115
|
-
RUBY
|
116
|
-
|
117
|
-
row :a_transform , :title , [:titleize] , "", <<-'RUBY'
|
118
|
-
tokenizer.parse(value,
|
119
|
-
separator: ' ',
|
120
|
-
preserve_case: true,
|
121
|
-
compress_prefix_numerals: false,
|
122
|
-
compress_suffix_numerals: false)
|
123
|
-
.titleize
|
124
|
-
RUBY
|
125
|
-
|
126
|
-
row :a_transform , :upper , [:upper_case, :upcase] , "", <<-'RUBY'
|
127
|
-
return '' if value.nil?
|
128
|
-
|
129
|
-
value.upcase
|
130
|
-
RUBY
|
131
|
-
|
132
|
-
|
133
|
-
row :a_comparison , :and , [:all] , "", <<-'RUBY'
|
134
|
-
values.all? { |value| value }
|
135
|
-
RUBY
|
136
|
-
|
137
|
-
# DEFAULT does not make sense in comparison
|
138
|
-
row :a_comparison , :default , [:fallback] , "", <<-'RUBY'
|
139
|
-
default_value = values[-1]
|
140
|
-
|
141
|
-
find_value = values[0..-2].find { |value| !value.nil? }
|
142
|
-
|
143
|
-
find_value || default_value
|
144
|
-
RUBY
|
145
|
-
|
146
|
-
row :a_comparison , :eq , [:equal] , "", <<-'RUBY'
|
147
|
-
lhs = lhs.to_s if lhs.is_a?(Symbol)
|
148
|
-
rhs = rhs.to_s if rhs.is_a?(Symbol)
|
149
|
-
|
150
|
-
lhs == rhs
|
151
|
-
RUBY
|
152
|
-
|
153
|
-
row :a_comparison , :gt , [] , "", <<-'RUBY'
|
154
|
-
lhs > rhs
|
155
|
-
RUBY
|
156
|
-
|
157
|
-
row :a_comparison , :gte , [] , "", <<-'RUBY'
|
158
|
-
lhs >= rhs
|
159
|
-
RUBY
|
160
|
-
|
161
|
-
row :a_comparison , :lt , [:less_than] , "# Lt: (less than) Block helper that renders a block if `a` is **less than** `b`. If an inverse block is specified it will be rendered when falsy.", <<-'RUBY'
|
162
|
-
lhs < rhs
|
163
|
-
RUBY
|
164
|
-
|
165
|
-
row :a_comparison , :lte , [:less_than_or_equal_to] , "# Lte: (less than or equal to) Block helper that renders a block if `a` is **less than or equal to** `b`. If an inverse block is specified it will be rendered when falsy.", <<-'RUBY'
|
166
|
-
lhs <= rhs
|
167
|
-
RUBY
|
168
|
-
|
169
|
-
row :a_comparison , :ne , [:not_equal] , "# Ne: (not equal) Block helper that renders a block if `a` is **not equal to** `b`. If an inverse block is specified it will be rendered when falsy.", <<-'RUBY'
|
170
|
-
lhs = lhs.to_s if lhs.is_a?(Symbol)
|
171
|
-
rhs = rhs.to_s if rhs.is_a?(Symbol)
|
172
|
-
|
173
|
-
lhs != rhs
|
174
|
-
RUBY
|
175
|
-
|
176
|
-
row :a_comparison , :or , [:any] , "", <<-'RUBY'
|
177
|
-
values.any? { |value| value }
|
178
|
-
RUBY
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
row :a_inflection , :ordinal , [] , "The suffix that should be added to a number to denote the position in an ordered sequence such as 1st, 2nd, 3rd, 4th", <<-RUBY
|
183
|
-
return '' if value.nil?
|
184
|
-
|
185
|
-
value = value.to_i if value.is_a? String
|
186
|
-
|
187
|
-
value.ordinal
|
188
|
-
RUBY
|
189
|
-
|
190
|
-
row :a_inflection , :ordinalize , [] , "Turns a number into an ordinal string used to denote the position in an ordered sequence such as 1st, 2nd, 3rd, 4th.", <<-RUBY
|
191
|
-
return '' if value.nil?
|
192
|
-
|
193
|
-
value = value.to_i if value.is_a? String
|
194
|
-
|
195
|
-
value.ordinalize
|
196
|
-
RUBY
|
197
|
-
|
198
|
-
row :a_inflection , :pluralize , [] , "Returns the plural form of the word in the string", <<-RUBY
|
199
|
-
return '' if value.nil?
|
200
|
-
|
201
|
-
value = value.to_s if value.is_a?(Symbol)
|
202
|
-
|
203
|
-
value.pluralize
|
204
|
-
RUBY
|
205
|
-
|
206
|
-
row :a_inflection , :pluralize_by_number , [] , "Uses both a word and number to decide if the plural or singular form should be used.", <<-'RUBY'
|
207
|
-
return '' if value.nil?
|
208
|
-
|
209
|
-
count = count.to_i if count.is_a? String
|
210
|
-
format = :word if format.nil?
|
211
|
-
|
212
|
-
case format.to_sym
|
213
|
-
when :number_word, :number_and_word
|
214
|
-
"#{count} #{value.pluralize(count)}"
|
215
|
-
else # aka :word
|
216
|
-
value.pluralize(count)
|
217
|
-
end
|
218
|
-
RUBY
|
219
|
-
|
220
|
-
# row :a_inflection , :singularize , [] , ""
|
221
|
-
end
|
222
|
-
end
|
223
|
-
|
224
|
-
@functions = result.raw_data_struct.rows
|
225
|
-
end
|
226
|
-
@functions = nil
|