cmdlet 0.0.6 → 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 +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
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class CategoryDao
|
4
|
+
attr_reader :k_builder
|
5
|
+
attr_reader :load_time
|
6
|
+
attr_reader :data
|
7
|
+
|
8
|
+
def initialize(k_builder)
|
9
|
+
@k_builder = k_builder
|
10
|
+
@load_time = nil
|
11
|
+
@data = nil
|
12
|
+
end
|
13
|
+
|
14
|
+
def file_name
|
15
|
+
k_builder.target_folders.join(:builder_data, 'categories.json')
|
16
|
+
end
|
17
|
+
|
18
|
+
def reload?
|
19
|
+
@load_time.nil? || @load_time < File.mtime(file_name)
|
20
|
+
end
|
21
|
+
|
22
|
+
def find_category(name)
|
23
|
+
result = categories.find { |category| category[:name] == name.to_s }
|
24
|
+
|
25
|
+
raise "Category #{name} not found" if result.nil?
|
26
|
+
|
27
|
+
result
|
28
|
+
end
|
29
|
+
|
30
|
+
def categories
|
31
|
+
if reload?
|
32
|
+
@data = JSON.parse(File.read(file_name), symbolize_names: true)
|
33
|
+
@categories = data[:categories]
|
34
|
+
@load_time = File.mtime(file_name)
|
35
|
+
end
|
36
|
+
@categories
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class CategoryDirector < KDirector::Directors::BaseDirector
|
4
|
+
defaults(builder_type: CategoryBuilder, on_exist: :write, on_action: :execute)
|
5
|
+
|
6
|
+
def category(name, description)
|
7
|
+
builder.category(name, description)
|
8
|
+
|
9
|
+
self
|
10
|
+
end
|
11
|
+
|
12
|
+
def generate
|
13
|
+
generate_require_all_cmdlets
|
14
|
+
|
15
|
+
self
|
16
|
+
end
|
17
|
+
|
18
|
+
def save_categories(**opts)
|
19
|
+
cd(:builder_data)
|
20
|
+
add('categories.json', content: builder.to_json, **opts)
|
21
|
+
|
22
|
+
self
|
23
|
+
end
|
24
|
+
|
25
|
+
def osave_categories(**opts)
|
26
|
+
save_categories(**{ open: true }.merge(opts))
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def generate_require_all_cmdlets
|
32
|
+
cd(:lib)
|
33
|
+
add('_.rb',
|
34
|
+
template_file: 'require_all_cmdlets.rb',
|
35
|
+
cmdlets: data_access.cmdlet.all_cmdlets)
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class CmdletBuilder < KDirector::Builders::ActionsBuilder
|
4
|
+
attr_reader :current_cmdlet
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
super
|
8
|
+
|
9
|
+
dom[:category_key] = nil
|
10
|
+
dom[:cmdlets] = []
|
11
|
+
end
|
12
|
+
|
13
|
+
def category_key
|
14
|
+
dom[:category_key]
|
15
|
+
end
|
16
|
+
|
17
|
+
def category_key=(value)
|
18
|
+
set(:category_key, value: value)
|
19
|
+
end
|
20
|
+
|
21
|
+
def cmdlets
|
22
|
+
dom[:cmdlets]
|
23
|
+
end
|
24
|
+
|
25
|
+
def add_cmdlet
|
26
|
+
@current_cmdlet = new_cmdlet
|
27
|
+
dom[:cmdlets] << current_cmdlet
|
28
|
+
end
|
29
|
+
|
30
|
+
def cmdlet_setting(name, value)
|
31
|
+
@current_cmdlet[name] = value
|
32
|
+
end
|
33
|
+
|
34
|
+
def add_cmdlet_parameter(name, description, **opts)
|
35
|
+
parameter = {
|
36
|
+
name: name,
|
37
|
+
description: description
|
38
|
+
}.merge(opts)
|
39
|
+
|
40
|
+
@current_cmdlet[:parameters] << parameter
|
41
|
+
end
|
42
|
+
|
43
|
+
def add_cmdlet_example(value)
|
44
|
+
lines = value.split("\n")
|
45
|
+
value = lines.map { |line| " # #{line.strip}" }.join("\n")
|
46
|
+
|
47
|
+
@current_cmdlet[:examples] << value
|
48
|
+
end
|
49
|
+
|
50
|
+
private
|
51
|
+
|
52
|
+
def new_cmdlet
|
53
|
+
category = data_access.category.find_category(category_key)
|
54
|
+
|
55
|
+
{
|
56
|
+
name: nil,
|
57
|
+
description: nil,
|
58
|
+
result: nil,
|
59
|
+
category: category[:name],
|
60
|
+
category_description: category[:description],
|
61
|
+
base_class_require: nil,
|
62
|
+
base_class: nil,
|
63
|
+
parameters: [],
|
64
|
+
examples: []
|
65
|
+
}
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class CmdletChild < KDirector::Directors::ChildDirector
|
4
|
+
def initialize(parent, **opts)
|
5
|
+
super(parent, **opts)
|
6
|
+
|
7
|
+
builder.add_cmdlet
|
8
|
+
end
|
9
|
+
|
10
|
+
def name(value)
|
11
|
+
builder.cmdlet_setting(:name, value)
|
12
|
+
end
|
13
|
+
|
14
|
+
def description(value)
|
15
|
+
builder.cmdlet_setting(:description, value)
|
16
|
+
end
|
17
|
+
|
18
|
+
def result(value)
|
19
|
+
builder.cmdlet_setting(:result, value)
|
20
|
+
end
|
21
|
+
|
22
|
+
def ruby(value)
|
23
|
+
builder.cmdlet_setting(:ruby, value)
|
24
|
+
end
|
25
|
+
|
26
|
+
def parameter(name, description, splat: nil, default: nil, param_type: 'String')
|
27
|
+
builder.add_cmdlet_parameter(
|
28
|
+
name,
|
29
|
+
description,
|
30
|
+
splat: splat,
|
31
|
+
default: default,
|
32
|
+
param_type: param_type
|
33
|
+
)
|
34
|
+
end
|
35
|
+
|
36
|
+
def example(value)
|
37
|
+
builder.add_cmdlet_example(value)
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class CmdletDao
|
4
|
+
attr_reader :k_builder
|
5
|
+
|
6
|
+
def initialize(k_builder)
|
7
|
+
@k_builder = k_builder
|
8
|
+
end
|
9
|
+
|
10
|
+
def all_cmdlets
|
11
|
+
data_access
|
12
|
+
.category
|
13
|
+
.categories.flat_map { |category| read_cmdlets(category[:name]) }
|
14
|
+
.compact
|
15
|
+
.uniq
|
16
|
+
.sort_by { |r| [r[:category], r[:name]] }
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def read_cmdlets(category_name)
|
22
|
+
file_name = k_builder.target_folders.join(:builder_data, 'cmdlets', "#{category_name}.json")
|
23
|
+
|
24
|
+
return JSON.parse(File.read(file_name), symbolize_names: true)[:cmdlets] if File.exist?(file_name)
|
25
|
+
|
26
|
+
puts "Cmdlet file #{file_name} not found"
|
27
|
+
nil
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class CmdletDirector < KDirector::Directors::BaseDirector
|
4
|
+
defaults(builder_type: CmdletBuilder, on_exist: :write, on_action: :execute)
|
5
|
+
|
6
|
+
def initialize(k_builder, builder, **opts)
|
7
|
+
super(k_builder, builder, **opts)
|
8
|
+
|
9
|
+
builder.category_key = opts[:category] || :unknown
|
10
|
+
end
|
11
|
+
|
12
|
+
def cmdlet(**opts, &block)
|
13
|
+
cmdlet = CmdletChild.new(self, **opts)
|
14
|
+
cmdlet.instance_eval(&block) if block_given?
|
15
|
+
|
16
|
+
self
|
17
|
+
end
|
18
|
+
|
19
|
+
def categories
|
20
|
+
data_access.category_director.categories
|
21
|
+
end
|
22
|
+
|
23
|
+
def generate
|
24
|
+
build_cmdlets
|
25
|
+
save_cmdlets
|
26
|
+
run_cop
|
27
|
+
|
28
|
+
self
|
29
|
+
end
|
30
|
+
|
31
|
+
def build_cmdlets
|
32
|
+
builder.cmdlets.each do |cmdlet|
|
33
|
+
cmdlet_file = "#{cmdlet[:category]}/#{cmdlet[:name]}.rb"
|
34
|
+
cmdlet_spec_file = "#{cmdlet[:category]}/#{cmdlet[:name]}_spec.rb"
|
35
|
+
|
36
|
+
cd(:lib)
|
37
|
+
add(cmdlet_file, template_file: 'cmdlet.rb', cmdlet: cmdlet)
|
38
|
+
|
39
|
+
cd(:spec)
|
40
|
+
add(cmdlet_spec_file, template_file: 'cmdlet_spec.rb', cmdlet: cmdlet, on_exist: :skip)
|
41
|
+
end
|
42
|
+
|
43
|
+
self
|
44
|
+
end
|
45
|
+
|
46
|
+
def run_cop
|
47
|
+
Dir.chdir(k_builder.target_folders.get(:app)) do
|
48
|
+
k_builder.run_cop('**/*.rb', fix_unsafe: true)
|
49
|
+
end
|
50
|
+
|
51
|
+
self
|
52
|
+
end
|
53
|
+
|
54
|
+
def save_cmdlets
|
55
|
+
cd(:builder_data)
|
56
|
+
add("cmdlets/#{builder.category_key}.json", content: builder.to_json)
|
57
|
+
|
58
|
+
self
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
def data_access
|
4
|
+
@data_access ||= Dao.new(k_builder)
|
5
|
+
end
|
6
|
+
|
7
|
+
class Dao
|
8
|
+
attr_reader :k_builder
|
9
|
+
attr_reader :category
|
10
|
+
attr_reader :cmdlet
|
11
|
+
|
12
|
+
def initialize(k_builder)
|
13
|
+
@category = CategoryDao.new(k_builder)
|
14
|
+
@cmdlet = CmdletDao.new(k_builder)
|
15
|
+
end
|
16
|
+
end
|
@@ -1,31 +1,225 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
def commands
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
4
|
+
return @commands unless @commands.nil?
|
5
|
+
|
6
|
+
result = KDoc.model :document do
|
7
|
+
table :rows do
|
8
|
+
fields :category, :name, :alias, :description, :ruby # , f(name: :params, default: [:value])
|
9
|
+
|
10
|
+
# context 'when array of string' do
|
11
|
+
# let(:value) { %w[the quick fox] }
|
12
|
+
|
13
|
+
# it { is_expected.to eq('the,quick,fox') }
|
14
|
+
# end
|
15
|
+
|
16
|
+
# context 'when array of numbers' do
|
17
|
+
# let(:value) { [1, 2, 3] }
|
18
|
+
|
19
|
+
# it { is_expected.to eq('1,2,3') }
|
20
|
+
# end
|
21
|
+
|
22
|
+
# context 'when array of symbol' do
|
23
|
+
# let(:value) { %i[the quick fox] }
|
24
|
+
|
25
|
+
# it { is_expected.to eq('the,quick,fox') }
|
26
|
+
# end
|
27
|
+
|
28
|
+
row :array , :join , [] , 'join an array of values with separator as a string', <<-'RUBY'
|
29
|
+
return '' if value.nil? || !value.is_a?(Array)
|
30
|
+
values = value.reject(&:blank?)
|
31
|
+
return '' if value.length.zero?
|
32
|
+
|
33
|
+
separator = ','
|
34
|
+
values.join(separator)
|
35
|
+
RUBY
|
36
|
+
|
37
|
+
row :array , :join_pre , [] , 'join an array of values with separator as a string and using the separator at the beginning of string', <<-'RUBY'
|
38
|
+
return '' if value.nil? || !value.is_a?(Array)
|
39
|
+
values = value.reject(&:blank?)
|
40
|
+
return '' if value.length.zero?
|
41
|
+
|
42
|
+
separator = ','
|
43
|
+
"#{separator}#{value.join(separator)}"
|
44
|
+
RUBY
|
45
|
+
|
46
|
+
# row :array , :join_post , [] , "join an array of values with separator as a string and using the separator at the end of string", <<-'RUBY'
|
47
|
+
# return '' if value.nil? || !value.is_a?(Array)
|
48
|
+
# values = value.reject(&:blank?)
|
49
|
+
# return '' if value.length.zero?
|
50
|
+
|
51
|
+
# separator = ','
|
52
|
+
# "#{value.join(separator)}#{separator}"
|
53
|
+
# RUBY
|
54
|
+
|
55
|
+
# row :a_transform , :backslash , [:back_slash] , "convert to back slash notation", <<-'RUBY'
|
56
|
+
# tokenizer.parse(value, preserve_case: true, separator: '\\')
|
57
|
+
# RUBY
|
58
|
+
|
59
|
+
# row :a_transform , :camel , [:upper_camel, :pascal] , "convert to camel notation", <<-'RUBY'
|
60
|
+
# tokenizer.parse(value).underscore.camelize
|
61
|
+
# RUBY
|
62
|
+
|
63
|
+
# row :a_transform , :constant , [:constantize] , "", <<-'RUBY'
|
64
|
+
# tokenizer.parse(value, separator: '_').upcase
|
65
|
+
# RUBY
|
66
|
+
|
67
|
+
# row :a_transform , :dash , [:dasherize] , "convert to dash notation", <<-'RUBY'
|
68
|
+
# tokenizer.parse(value)
|
69
|
+
# RUBY
|
70
|
+
|
71
|
+
# row :a_transform , :dot , [:dotirize] , "", <<-'RUBY'
|
72
|
+
# tokenizer.parse(value, separator: '.')
|
73
|
+
# RUBY
|
74
|
+
|
75
|
+
# row :a_transform , :double_colon , [] , "", <<-'RUBY'
|
76
|
+
# tokenizer.parse(value, preserve_case: true, separator: '::')
|
77
|
+
# RUBY
|
78
|
+
|
79
|
+
# row :a_transform , :lower , [:lowercase, :downcase] , "", <<-'RUBY'
|
80
|
+
# return '' if value.nil?
|
81
|
+
|
82
|
+
# value.downcase
|
83
|
+
# RUBY
|
84
|
+
|
85
|
+
# # row :a_transform , :format_as , [] , "", <<-'RUBY'
|
86
|
+
|
87
|
+
# # RUBY
|
88
|
+
|
89
|
+
# row :a_transform , :proper , [] , "Proper case capitalizes the first letter of ALL words in a string", <<-'RUBY'
|
90
|
+
# tokenizer.parse(value,
|
91
|
+
# separator: ' ',
|
92
|
+
# preserve_case: true,
|
93
|
+
# compress_prefix_numerals: false,
|
94
|
+
# compress_suffix_numerals: false)
|
95
|
+
# .titleize
|
96
|
+
# RUBY
|
97
|
+
|
98
|
+
# row :a_transform , :sentence , [:human, :humanize] , "Upper case for first letter only. Numbers will maintain their spacing", <<-'RUBY'
|
99
|
+
# tokenizer.parse(value,
|
100
|
+
# separator: ' ',
|
101
|
+
# preserve_case: true,
|
102
|
+
# compress_prefix_numerals: false,
|
103
|
+
# compress_suffix_numerals: false)
|
104
|
+
# .humanize
|
105
|
+
# RUBY
|
106
|
+
|
107
|
+
# row :a_transform , :lamel , [:lower_camel] , "", <<-'RUBY'
|
108
|
+
# tokenizer.parse(value, separator: '_').camelize(:lower)
|
109
|
+
# RUBY
|
110
|
+
|
111
|
+
# row :a_transform , :slash , [:forwardslash, :forward_slash] , "", <<-'RUBY'
|
112
|
+
# tokenizer.parse(value, preserve_case: true, separator: '/')
|
113
|
+
# RUBY
|
114
|
+
|
115
|
+
# row :a_transform , :snake , [:snake] , "", <<-'RUBY'
|
116
|
+
# tokenizer.parse(value, separator: '_', forced_separator: true)
|
117
|
+
# RUBY
|
118
|
+
|
119
|
+
# row :a_transform , :title , [:titleize] , "", <<-'RUBY'
|
120
|
+
# tokenizer.parse(value,
|
121
|
+
# separator: ' ',
|
122
|
+
# preserve_case: true,
|
123
|
+
# compress_prefix_numerals: false,
|
124
|
+
# compress_suffix_numerals: false)
|
125
|
+
# .titleize
|
126
|
+
# RUBY
|
127
|
+
|
128
|
+
# row :a_transform , :upper , [:upper_case, :upcase] , "", <<-'RUBY'
|
129
|
+
# return '' if value.nil?
|
130
|
+
|
131
|
+
# value.upcase
|
132
|
+
# RUBY
|
133
|
+
|
134
|
+
# row :a_comparison , :and , [:all] , "", <<-'RUBY'
|
135
|
+
# values.all? { |value| value }
|
136
|
+
# RUBY
|
137
|
+
|
138
|
+
# # DEFAULT does not make sense in comparison
|
139
|
+
# row :a_comparison , :default , [:fallback] , "", <<-'RUBY'
|
140
|
+
# default_value = values[-1]
|
141
|
+
|
142
|
+
# find_value = values[0..-2].find { |value| !value.nil? }
|
143
|
+
|
144
|
+
# find_value || default_value
|
145
|
+
# RUBY
|
146
|
+
|
147
|
+
# row :a_comparison , :eq , [:equal] , "", <<-'RUBY'
|
148
|
+
# lhs = lhs.to_s if lhs.is_a?(Symbol)
|
149
|
+
# rhs = rhs.to_s if rhs.is_a?(Symbol)
|
150
|
+
|
151
|
+
# lhs == rhs
|
152
|
+
# RUBY
|
153
|
+
|
154
|
+
# row :a_comparison , :gt , [] , "", <<-'RUBY'
|
155
|
+
# lhs > rhs
|
156
|
+
# RUBY
|
157
|
+
|
158
|
+
# row :a_comparison , :gte , [] , "", <<-'RUBY'
|
159
|
+
# lhs >= rhs
|
160
|
+
# RUBY
|
161
|
+
|
162
|
+
# 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'
|
163
|
+
# lhs < rhs
|
164
|
+
# RUBY
|
165
|
+
|
166
|
+
# 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'
|
167
|
+
# lhs <= rhs
|
168
|
+
# RUBY
|
169
|
+
|
170
|
+
# 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'
|
171
|
+
# lhs = lhs.to_s if lhs.is_a?(Symbol)
|
172
|
+
# rhs = rhs.to_s if rhs.is_a?(Symbol)
|
173
|
+
|
174
|
+
# lhs != rhs
|
175
|
+
# RUBY
|
176
|
+
|
177
|
+
# row :a_comparison , :or , [:any] , "", <<-'RUBY'
|
178
|
+
# values.any? { |value| value }
|
179
|
+
# RUBY
|
180
|
+
|
181
|
+
# 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
|
182
|
+
# return '' if value.nil?
|
183
|
+
|
184
|
+
# value = value.to_i if value.is_a? String
|
185
|
+
|
186
|
+
# value.ordinal
|
187
|
+
# RUBY
|
188
|
+
|
189
|
+
# 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
|
190
|
+
# return '' if value.nil?
|
191
|
+
|
192
|
+
# value = value.to_i if value.is_a? String
|
193
|
+
|
194
|
+
# value.ordinalize
|
195
|
+
# RUBY
|
196
|
+
|
197
|
+
# row :a_inflection , :pluralize , [] , "Returns the plural form of the word in the string", <<-RUBY
|
198
|
+
# return '' if value.nil?
|
199
|
+
|
200
|
+
# value = value.to_s if value.is_a?(Symbol)
|
201
|
+
|
202
|
+
# value.pluralize
|
203
|
+
# RUBY
|
204
|
+
|
205
|
+
# row :a_inflection , :pluralize_by_number , [] , "Uses both a word and number to decide if the plural or singular form should be used.", <<-'RUBY'
|
206
|
+
# return '' if value.nil?
|
207
|
+
|
208
|
+
# count = count.to_i if count.is_a? String
|
209
|
+
# format = :word if format.nil?
|
210
|
+
|
211
|
+
# case format.to_sym
|
212
|
+
# when :number_word, :number_and_word
|
213
|
+
# "#{count} #{value.pluralize(count)}"
|
214
|
+
# else # aka :word
|
215
|
+
# value.pluralize(count)
|
216
|
+
# end
|
217
|
+
# RUBY
|
218
|
+
|
219
|
+
# row :a_inflection , :singularize , [] , ""
|
220
|
+
end
|
26
221
|
end
|
27
|
-
end
|
28
222
|
|
29
|
-
|
30
|
-
|
31
|
-
|
223
|
+
@commands = result.raw_data_struct.rows
|
224
|
+
end
|
225
|
+
@commands = nil
|
@@ -1,8 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
def use_cases
|
2
4
|
return @use_cases unless @use_cases.nil?
|
3
|
-
|
4
|
-
result = KDoc.model :document do
|
5
5
|
|
6
|
+
result = KDoc.model :document do
|
6
7
|
# table :inputs do
|
7
8
|
# fields :name, :value
|
8
9
|
|
@@ -18,9 +19,9 @@ def use_cases
|
|
18
19
|
|
19
20
|
# end
|
20
21
|
|
21
|
-
sentence1 =
|
22
|
-
sentence2 =
|
23
|
-
text1 =
|
22
|
+
sentence1 = 'The quick brown fox, jumped over the lazy dog'
|
23
|
+
sentence2 = 'coyote and the acme company'
|
24
|
+
text1 = 'the Quick brown Fox 99'
|
24
25
|
|
25
26
|
table :rows do
|
26
27
|
# fields :category, :function, :input, :commands, :expected_value
|
@@ -62,37 +63,36 @@ def use_cases
|
|
62
63
|
row :a_transform , :title , [text1] , 'The Quick Brown Fox 99'
|
63
64
|
row :a_transform , :title , [sentence1] , 'The Quick Brown Fox Jumped over the Lazy Dog'
|
64
65
|
row :a_transform , :upper , [text1] , 'THE QUICK BROWN FOX 99'
|
65
|
-
|
66
66
|
|
67
67
|
row :a_comparison , :and , [nil, nil] , false
|
68
68
|
row :a_comparison , :and , ['data', nil] , false
|
69
69
|
row :a_comparison , :and , [nil, 'data'] , false
|
70
|
-
row :a_comparison , :and , [
|
71
|
-
row :a_comparison , :and , [
|
70
|
+
row :a_comparison , :and , %w[data data] , true
|
71
|
+
row :a_comparison , :and , %w[aaa bbb] , true
|
72
72
|
|
73
73
|
# DEFAULT does not make sense in comparison
|
74
|
-
row :a_comparison , :default , [nil, 'happy'] ,
|
75
|
-
row :a_comparison , :default , [
|
76
|
-
row :a_comparison , :default , [nil, nil, nil, nil, 'david'] ,
|
77
|
-
row :a_comparison , :default , ['', 'happy'] ,
|
74
|
+
row :a_comparison , :default , [nil, 'happy'] , 'happy'
|
75
|
+
row :a_comparison , :default , %w[sad happy] , 'sad'
|
76
|
+
row :a_comparison , :default , [nil, nil, nil, nil, 'david'] , 'david'
|
77
|
+
row :a_comparison , :default , ['', 'happy'] , 'happy'
|
78
78
|
|
79
79
|
# type: :strict, :equiv, :cast, :insensitive
|
80
|
-
row :a_comparison , :eq , [111, '111'
|
81
|
-
row :a_comparison , :eq , [111, 111.0
|
82
|
-
row :a_comparison , :eq , [
|
83
|
-
row :a_comparison , :eq , [
|
84
|
-
row :a_comparison , :eq , [
|
80
|
+
row :a_comparison , :eq , [111, '111'], false
|
81
|
+
row :a_comparison , :eq , [111, 111.0], false
|
82
|
+
row :a_comparison , :eq , %w[aaa aaa], true
|
83
|
+
row :a_comparison , :eq , %w[aaa bbb], false
|
84
|
+
row :a_comparison , :eq , %i[aaa aaa] , true
|
85
85
|
row :a_comparison , :eq , ['aaa', :aaa] , false
|
86
|
-
row :a_comparison , :eq , [
|
87
|
-
row :a_comparison , :eq , [
|
86
|
+
row :a_comparison , :eq , %w[aaa bbb], false
|
87
|
+
row :a_comparison , :eq , %w[aaa AAA], false
|
88
88
|
|
89
89
|
row :a_comparison , :gt , [2, 1] , true
|
90
90
|
row :a_comparison , :gt , [2, 2] , false
|
91
|
-
|
91
|
+
|
92
92
|
row :a_comparison , :gte , [1, 2] , false
|
93
93
|
row :a_comparison , :gte , [1, 1] , true
|
94
94
|
row :a_comparison , :gte , [2, 1] , true
|
95
|
-
|
95
|
+
|
96
96
|
row :a_comparison , :lt , [1, 2] , true
|
97
97
|
row :a_comparison , :lt , [2, 1] , false
|
98
98
|
|
@@ -102,16 +102,15 @@ def use_cases
|
|
102
102
|
|
103
103
|
row :a_comparison , :ne , [1, 2] , true
|
104
104
|
row :a_comparison , :ne , [1, 1] , false
|
105
|
-
|
105
|
+
|
106
106
|
row :a_comparison , :or , [nil, nil] , false
|
107
107
|
row :a_comparison , :or , ['data', nil] , true
|
108
108
|
row :a_comparison , :or , [nil, 'data'] , true
|
109
|
-
row :a_comparison , :or , [
|
110
|
-
row :a_comparison , :or , [
|
109
|
+
row :a_comparison , :or , %w[data data] , true
|
110
|
+
row :a_comparison , :or , %w[aaa bbb] , true
|
111
111
|
# row :text1 , %i[backslash] , 'the\quick\brown\fox99'
|
112
112
|
# row :text1 , %i[camel] , 'TheQuickBrownFox99'
|
113
113
|
|
114
|
-
|
115
114
|
# row :sentence3 , %i[plural] , "jumped over the lazy dogs"
|
116
115
|
# row :title , %i[plural] , "Account Categories"
|
117
116
|
# row :sentence1 , %i[dash] , "The-quick-brown-fox-jumped-over-the-lazy-dog"
|
@@ -120,17 +119,16 @@ def use_cases
|
|
120
119
|
# row :bsb_account , %i[lower snake] , "abc_123"
|
121
120
|
# row :bsb_account , %i[slash] , "ABC/123"
|
122
121
|
end
|
123
|
-
|
124
122
|
end
|
125
|
-
|
123
|
+
|
126
124
|
@use_cases = result.raw_data_struct.rows
|
127
125
|
end
|
128
126
|
@use_cases = nil
|
129
127
|
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
128
|
+
# def self.camel_case(string, tokenizer = PreservePrefixedUnderscoreTokenizer.new)
|
129
|
+
# # DAVE INPUT 9 Oct 21 from lucky_case play
|
130
|
+
# # dependency injection: to use enhanced tokenizer
|
131
|
+
# a = split_case_string string
|
132
|
+
# converted = ([a[0]] + a[1..-1].map { |e| capital e }).join('')
|
133
|
+
# tokenizer.parse(converted)
|
134
|
+
# end
|