cooklang 0.1.0 → 1.0.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.
Files changed (59) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/test.yml +35 -0
  3. data/.gitignore +12 -0
  4. data/.qlty/.gitignore +7 -0
  5. data/.qlty/configs/.yamllint.yaml +21 -0
  6. data/.qlty/qlty.toml +101 -0
  7. data/.rspec +3 -0
  8. data/.rubocop.yml +289 -75
  9. data/Gemfile.lock +65 -26
  10. data/{LICENSE → LICENSE.txt} +6 -6
  11. data/README.md +106 -12
  12. data/Rakefile +5 -1
  13. data/cooklang.gemspec +35 -0
  14. data/lib/cooklang/builders/recipe_builder.rb +64 -0
  15. data/lib/cooklang/builders/step_builder.rb +76 -0
  16. data/lib/cooklang/cookware.rb +43 -0
  17. data/lib/cooklang/formatter.rb +61 -0
  18. data/lib/cooklang/formatters/text.rb +18 -0
  19. data/lib/cooklang/ingredient.rb +60 -0
  20. data/lib/cooklang/lexer.rb +282 -0
  21. data/lib/cooklang/metadata.rb +98 -0
  22. data/lib/cooklang/note.rb +27 -0
  23. data/lib/cooklang/parser.rb +41 -0
  24. data/lib/cooklang/parsers/cookware_parser.rb +133 -0
  25. data/lib/cooklang/parsers/ingredient_parser.rb +179 -0
  26. data/lib/cooklang/parsers/timer_parser.rb +135 -0
  27. data/lib/cooklang/processors/element_parser.rb +45 -0
  28. data/lib/cooklang/processors/metadata_processor.rb +129 -0
  29. data/lib/cooklang/processors/step_processor.rb +208 -0
  30. data/lib/cooklang/processors/token_processor.rb +104 -0
  31. data/lib/cooklang/recipe.rb +72 -0
  32. data/lib/cooklang/section.rb +33 -0
  33. data/lib/cooklang/step.rb +99 -0
  34. data/lib/cooklang/timer.rb +65 -0
  35. data/lib/cooklang/token_stream.rb +130 -0
  36. data/lib/cooklang/version.rb +1 -1
  37. data/lib/cooklang.rb +22 -1
  38. data/spec/comprehensive_spec.rb +179 -0
  39. data/spec/cooklang_spec.rb +38 -0
  40. data/spec/fixtures/canonical.yaml +837 -0
  41. data/spec/formatters/text_spec.rb +189 -0
  42. data/spec/integration/canonical_spec.rb +211 -0
  43. data/spec/lexer_spec.rb +357 -0
  44. data/spec/models/cookware_spec.rb +116 -0
  45. data/spec/models/ingredient_spec.rb +192 -0
  46. data/spec/models/metadata_spec.rb +241 -0
  47. data/spec/models/note_spec.rb +65 -0
  48. data/spec/models/recipe_spec.rb +171 -0
  49. data/spec/models/section_spec.rb +65 -0
  50. data/spec/models/step_spec.rb +236 -0
  51. data/spec/models/timer_spec.rb +173 -0
  52. data/spec/parser_spec.rb +398 -0
  53. data/spec/spec_helper.rb +23 -0
  54. data/spec/token_stream_spec.rb +278 -0
  55. metadata +141 -24
  56. data/.ruby-version +0 -1
  57. data/CHANGELOG.md +0 -5
  58. data/bin/console +0 -15
  59. data/bin/setup +0 -8
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6695e5e9c9b98ec1aa80cd6cda05909fd39008454e3667761516365874a28054
4
- data.tar.gz: 70d755aeed7e1ef4810d1a797a471740adaeddd5382a031abdf0e972a8f5a827
3
+ metadata.gz: c61d7de5e0471ab52eb21411d501fb1b909a5e1c356b2eeb105a37c971847321
4
+ data.tar.gz: 24fb626c2590541600acf57b317255adbb6fa75abc34ace698c70c8fcf2a5c90
5
5
  SHA512:
6
- metadata.gz: 7799cc3b498d4ebb8f519af4c3dbf50ced4618afe29a724cbfb83702bf95f52360e1e390bbb186d101bdf0e2a05eca30fcf5915e6007ca0c29bfaeb0b7df0abd
7
- data.tar.gz: 04bafd2e069bbd3192ef617b15d3a71f3c951232053bf4a9b656d94c74814f9a46d59393ae11bc9a8ead3fc2b2758db61cd4b7e77aa75598dede89e51e5939dd
6
+ metadata.gz: 723008d0a4ea83eaec6c376f715f47a74edf29230a2fb8fcc2ec13d47250b65adc6027511343de7a6bd3e4d2b833e592add88373e298bf21e98a1fa217358166
7
+ data.tar.gz: ff3a2b9eb011b525309a7ac19bda34c51eb9dd68f154958af8b164511b1955a61e786dfd3cb45dd51391682700b9b962e2b3a8f54bade6fc1a5d56ea4053b2b3
@@ -0,0 +1,35 @@
1
+ name: Test
2
+
3
+ on:
4
+ push:
5
+ branches: [ main, master ]
6
+ pull_request:
7
+ branches: [ main, master ]
8
+
9
+ jobs:
10
+ test:
11
+ runs-on: ubuntu-latest
12
+ strategy:
13
+ matrix:
14
+ ruby-version: ['3.2', '3.3', '3.4', '3.5']
15
+
16
+ steps:
17
+ - uses: actions/checkout@v4
18
+
19
+ - name: Set up Ruby ${{ matrix.ruby-version }}
20
+ uses: ruby/setup-ruby@v1
21
+ with:
22
+ ruby-version: ${{ matrix.ruby-version }}
23
+ bundler-cache: true
24
+
25
+ - name: Run tests
26
+ run: bundle exec rspec
27
+
28
+ - name: Run RuboCop
29
+ run: bundle exec rubocop
30
+
31
+ - uses: qltysh/qlty-action/coverage@v2
32
+ if: matrix.ruby-version == '3.5'
33
+ with:
34
+ token: ${{ secrets.QLTY_COVERAGE_TOKEN }}
35
+ files: coverage/.resultset.json
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ /*.gem
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
data/.qlty/.gitignore ADDED
@@ -0,0 +1,7 @@
1
+ *
2
+ !configs
3
+ !configs/**
4
+ !hooks
5
+ !hooks/**
6
+ !qlty.toml
7
+ !.gitignore
@@ -0,0 +1,21 @@
1
+ extends: default
2
+
3
+ rules:
4
+ document-start: disable
5
+ quoted-strings:
6
+ required: only-when-needed
7
+ extra-allowed: ["{|}"]
8
+ key-duplicates: {}
9
+ octal-values:
10
+ forbid-implicit-octal: true
11
+ line-length: disable
12
+ indentation: disable
13
+ new-line-at-end-of-file: disable
14
+ trailing-spaces: disable
15
+ brackets: disable
16
+ colons: disable
17
+ empty-lines: disable
18
+ comments: disable
19
+ braces: disable
20
+ comments-indentation: disable
21
+ commas: disable
data/.qlty/qlty.toml ADDED
@@ -0,0 +1,101 @@
1
+ # This file was automatically generated by `qlty init`.
2
+ # You can modify it to suit your needs.
3
+ # We recommend you to commit this file to your repository.
4
+ #
5
+ # This configuration is used by both Qlty CLI and Qlty Cloud.
6
+ #
7
+ # Qlty CLI -- Code quality toolkit for developers
8
+ # Qlty Cloud -- Fully automated Code Health Platform
9
+ #
10
+ # Try Qlty Cloud: https://qlty.sh
11
+ #
12
+ # For a guide to configuration, visit https://qlty.sh/d/config
13
+ # Or for a full reference, visit https://qlty.sh/d/qlty-toml
14
+ config_version = "0"
15
+
16
+ exclude_patterns = [
17
+ "*_min.*",
18
+ "*-min.*",
19
+ "*.min.*",
20
+ "**/.yarn/**",
21
+ "**/*.d.ts",
22
+ "**/assets/**",
23
+ "**/bower_components/**",
24
+ "**/build/**",
25
+ "**/cache/**",
26
+ "**/config/**",
27
+ "**/db/**",
28
+ "**/deps/**",
29
+ "**/dist/**",
30
+ "**/extern/**",
31
+ "**/external/**",
32
+ "**/generated/**",
33
+ "**/Godeps/**",
34
+ "**/gradlew/**",
35
+ "**/mvnw/**",
36
+ "**/node_modules/**",
37
+ "**/protos/**",
38
+ "**/seed/**",
39
+ "**/target/**",
40
+ "**/templates/**",
41
+ "**/testdata/**",
42
+ "**/vendor/**",
43
+ "**/.rubocop.yml",
44
+ "**.github/**",
45
+ "**/spec/fixtures/canonical.yaml",
46
+ ]
47
+
48
+ test_patterns = [
49
+ "**/test/**",
50
+ "**/spec/**",
51
+ "**/*.test.*",
52
+ "**/*.spec.*",
53
+ "**/*_test.*",
54
+ "**/*_spec.*",
55
+ "**/test_*.*",
56
+ "**/spec_*.*",
57
+ ]
58
+
59
+ [smells]
60
+ mode = "comment"
61
+
62
+ [[source]]
63
+ name = "default"
64
+ default = true
65
+
66
+
67
+ [[plugin]]
68
+ name = "actionlint"
69
+
70
+ [[plugin]]
71
+ name = "markdownlint"
72
+ drivers = [
73
+ "lint",
74
+ ]
75
+ mode = "comment"
76
+
77
+ [[plugin]]
78
+ name = "osv-scanner"
79
+
80
+ [[plugin]]
81
+ name = "ripgrep"
82
+ mode = "comment"
83
+
84
+ [[plugin]]
85
+ name = "rubocop"
86
+ version = "1.80.0"
87
+ package_file = "Gemfile"
88
+ package_filters = ["rubocop"]
89
+
90
+ [[plugin]]
91
+ name = "trivy"
92
+ drivers = [
93
+ "config",
94
+ "fs-vuln",
95
+ ]
96
+
97
+ [[plugin]]
98
+ name = "trufflehog"
99
+
100
+ [[plugin]]
101
+ name = "yamllint"
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml CHANGED
@@ -1,126 +1,340 @@
1
- require:
1
+ plugins:
2
2
  - rubocop-performance
3
3
  - rubocop-rspec
4
4
 
5
5
  AllCops:
6
- TargetRubyVersion: 2.7.5
7
- NewCops: enable
6
+ DisabledByDefault: true
7
+ SuggestExtensions: false
8
8
 
9
- Bundler/OrderedGems:
10
- Enabled: false
9
+ # Prefer &&/|| over and/or.
10
+ Style/AndOr:
11
+ Enabled: true
11
12
 
12
- Layout/AccessModifierIndentation:
13
- EnforcedStyle: outdent
13
+ Layout/ClosingHeredocIndentation:
14
+ Enabled: true
14
15
 
15
- Layout/CaseIndentation:
16
- EnforcedStyle: end
16
+ Layout/ClosingParenthesisIndentation:
17
+ Enabled: true
17
18
 
18
- Layout/EmptyLinesAroundAccessModifier:
19
- EnforcedStyle: only_before
19
+ # Align comments with method definitions.
20
+ Layout/CommentIndentation:
21
+ Enabled: true
22
+
23
+ Layout/DefEndAlignment:
24
+ Enabled: true
25
+
26
+ Layout/ElseAlignment:
27
+ Enabled: true
20
28
 
29
+ # Align `end` with the matching keyword or starting expression except for
30
+ # assignments, where it should be aligned with the LHS.
21
31
  Layout/EndAlignment:
32
+ Enabled: true
22
33
  EnforcedStyleAlignWith: variable
34
+ AutoCorrect: true
23
35
 
24
- Layout/FirstArrayElementIndentation:
25
- EnforcedStyle: consistent
36
+ Layout/EndOfLine:
37
+ Enabled: true
26
38
 
27
- Layout/FirstHashElementIndentation:
28
- EnforcedStyle: consistent
39
+ Layout/EmptyLineAfterMagicComment:
40
+ Enabled: true
29
41
 
30
- Layout/LineLength:
31
- Max: 120
42
+ Layout/EmptyLinesAroundAccessModifier:
43
+ Enabled: true
44
+ EnforcedStyle: only_before
32
45
 
33
- Layout/MultilineMethodCallIndentation:
34
- EnforcedStyle: indented
46
+ Layout/EmptyLinesAroundBlockBody:
47
+ Enabled: true
35
48
 
36
- Layout/SpaceInsideArrayLiteralBrackets:
37
- EnforcedStyle: space
49
+ # In a regular class definition, no empty lines around the body.
50
+ Layout/EmptyLinesAroundClassBody:
51
+ Enabled: true
38
52
 
39
- Metrics/AbcSize:
40
- Enabled: false
53
+ # In a regular method definition, no empty lines around the body.
54
+ Layout/EmptyLinesAroundMethodBody:
55
+ Enabled: true
41
56
 
42
- Metrics/BlockLength:
43
- Enabled: false
57
+ # In a regular module definition, no empty lines around the body.
58
+ Layout/EmptyLinesAroundModuleBody:
59
+ Enabled: true
44
60
 
45
- Metrics/ClassLength:
46
- Enabled: false
61
+ # Use Ruby >= 1.9 syntax for hashes. Prefer { a: :b } over { :a => :b }.
62
+ Style/HashSyntax:
63
+ Enabled: true
64
+ EnforcedShorthandSyntax: either
47
65
 
48
- Metrics/CyclomaticComplexity:
49
- Enabled: false
66
+ # Method definitions after `private` or `protected` isolated calls need one
67
+ # extra level of indentation.
68
+ Layout/IndentationConsistency:
69
+ Enabled: true
70
+ EnforcedStyle: indented_internal_methods
71
+ Exclude:
72
+ - '**/*.md'
50
73
 
51
- Metrics/MethodLength:
52
- Enabled: false # with constructing a lot of bulky hashes this cop becomes noisy
74
+ # Two spaces, no tabs (for indentation).
75
+ Layout/IndentationWidth:
76
+ Enabled: true
53
77
 
54
- Metrics/ParameterLists:
55
- CountKeywordArgs: false
78
+ Layout/LeadingCommentSpace:
79
+ Enabled: true
56
80
 
57
- Metrics/PerceivedComplexity:
58
- Enabled: false
81
+ Layout/SpaceAfterColon:
82
+ Enabled: true
59
83
 
60
- Naming/AccessorMethodName:
61
- Enabled: false
84
+ Layout/SpaceAfterComma:
85
+ Enabled: true
62
86
 
63
- Naming/InclusiveLanguage:
64
- Enabled: false
87
+ Layout/SpaceAfterSemicolon:
88
+ Enabled: true
65
89
 
66
- RSpec/EmptyLineAfterSubject:
67
- Enabled: false
90
+ Layout/SpaceAroundEqualsInParameterDefault:
91
+ Enabled: true
68
92
 
69
- RSpec/ExampleLength:
70
- Max: 10
93
+ Layout/SpaceAroundKeyword:
94
+ Enabled: true
71
95
 
72
- RSpec/MultipleSubjects:
73
- Enabled: false
96
+ Layout/SpaceAroundOperators:
97
+ Enabled: true
74
98
 
75
- Style/AndOr:
76
- Enabled: false
99
+ Layout/SpaceBeforeComma:
100
+ Enabled: true
77
101
 
78
- Style/ClassAndModuleChildren:
79
- Enabled: false
102
+ Layout/SpaceBeforeComment:
103
+ Enabled: true
80
104
 
81
- Style/ConditionalAssignment:
82
- Enabled: false
105
+ Layout/SpaceBeforeFirstArg:
106
+ Enabled: true
107
+
108
+ Style/DefWithParentheses:
109
+ Enabled: true
110
+
111
+ # Defining a method with parameters needs parentheses.
112
+ Style/MethodDefParentheses:
113
+ Enabled: true
83
114
 
84
- Style/Documentation:
85
- Enabled: false
115
+ Style/ExplicitBlockArgument:
116
+ Enabled: true
86
117
 
87
118
  Style/FrozenStringLiteralComment:
88
- Enabled: false
119
+ Enabled: true
120
+ EnforcedStyle: always
121
+ Exclude:
122
+ - 'actionview/test/**/*.builder'
123
+ - 'actionview/test/**/*.ruby'
124
+ - 'actionpack/test/**/*.builder'
125
+ - 'actionpack/test/**/*.ruby'
126
+ - 'activestorage/db/migrate/**/*.rb'
127
+ - 'activestorage/db/update_migrate/**/*.rb'
128
+ - 'actionmailbox/db/migrate/**/*.rb'
129
+ - 'actiontext/db/migrate/**/*.rb'
130
+ - '**/*.md'
131
+
132
+ Style/MapToHash:
133
+ Enabled: true
134
+
135
+ Style/RedundantFreeze:
136
+ Enabled: true
137
+
138
+ # Use `foo {}` not `foo{}`.
139
+ Layout/SpaceBeforeBlockBraces:
140
+ Enabled: true
141
+
142
+ # Use `foo { bar }` not `foo {bar}`.
143
+ Layout/SpaceInsideBlockBraces:
144
+ Enabled: true
145
+ EnforcedStyleForEmptyBraces: space
146
+
147
+ # Use `{ a: 1 }` not `{a:1}`.
148
+ Layout/SpaceInsideHashLiteralBraces:
149
+ Enabled: true
150
+
151
+ Layout/SpaceInsideParens:
152
+ Enabled: true
153
+
154
+ # Check quotes usage according to lint rule below.
155
+ Style/StringLiterals:
156
+ Enabled: true
157
+ EnforcedStyle: double_quotes
158
+
159
+ # Detect hard tabs, no hard tabs.
160
+ Layout/IndentationStyle:
161
+ Enabled: true
162
+
163
+ # Empty lines should not have any spaces.
164
+ Layout/TrailingEmptyLines:
165
+ Enabled: true
166
+
167
+ # No trailing whitespace.
168
+ Layout/TrailingWhitespace:
169
+ Enabled: true
170
+
171
+ # Use quotes for string literals when they are enough.
172
+ Style/RedundantPercentQ:
173
+ Enabled: true
174
+
175
+ Lint/NestedMethodDefinition:
176
+ Enabled: true
177
+
178
+ Lint/AmbiguousOperator:
179
+ Enabled: true
180
+
181
+ Lint/AmbiguousRegexpLiteral:
182
+ Enabled: true
183
+
184
+ Lint/Debugger:
185
+ Enabled: true
186
+ DebuggerRequires:
187
+ - debug
188
+
189
+ Lint/DuplicateRequire:
190
+ Enabled: true
191
+
192
+ Lint/DuplicateMagicComment:
193
+ Enabled: true
194
+
195
+ Lint/DuplicateMethods:
196
+ Enabled: true
89
197
 
90
- Style/GuardClause:
91
- Enabled: false
198
+ Lint/ErbNewArguments:
199
+ Enabled: true
200
+
201
+ Lint/EnsureReturn:
202
+ Enabled: true
203
+
204
+ Lint/MissingCopEnableDirective:
205
+ Enabled: true
206
+
207
+ # Use my_method(my_arg) not my_method( my_arg ) or my_method my_arg.
208
+ Lint/RequireParentheses:
209
+ Enabled: true
210
+
211
+ Lint/RedundantCopDisableDirective:
212
+ Enabled: true
213
+
214
+ Lint/RedundantCopEnableDirective:
215
+ Enabled: true
216
+
217
+ Lint/RedundantRequireStatement:
218
+ Enabled: true
219
+
220
+ Lint/RedundantStringCoercion:
221
+ Enabled: true
92
222
 
93
- Style/HashEachMethods:
223
+ Lint/RedundantSafeNavigation:
224
+ Enabled: true
225
+
226
+ Lint/UriEscapeUnescape:
227
+ Enabled: true
228
+
229
+ Lint/UselessAssignment:
230
+ Enabled: true
231
+
232
+ Lint/DeprecatedClassMethods:
233
+ Enabled: true
234
+
235
+ Lint/InterpolationCheck:
236
+ Enabled: true
237
+ Exclude:
238
+ - '**/test/**/*'
239
+
240
+ Lint/SafeNavigationChain:
241
+ Enabled: true
242
+
243
+ Style/EvalWithLocation:
244
+ Enabled: true
245
+ Exclude:
246
+ - '**/test/**/*'
247
+
248
+ Style/ParenthesesAroundCondition:
94
249
  Enabled: true
95
250
 
96
251
  Style/HashTransformKeys:
97
- Enabled: false
252
+ Enabled: true
98
253
 
99
254
  Style/HashTransformValues:
100
- Enabled: false
255
+ Enabled: true
101
256
 
102
- Style/IfUnlessModifier:
103
- Enabled: false
257
+ Style/RedundantBegin:
258
+ Enabled: true
104
259
 
105
- Style/IfWithBooleanLiteralBranches:
106
- Enabled: false
260
+ Style/RedundantReturn:
261
+ Enabled: true
262
+ AllowMultipleReturnValues: true
107
263
 
108
- Style/Lambda:
109
- Enabled: false
264
+ Style/RedundantRegexpEscape:
265
+ Enabled: true
110
266
 
111
- Style/QuotedSymbols:
112
- Enabled: false
267
+ Style/Semicolon:
268
+ Enabled: true
269
+ AllowAsExpressionSeparator: true
113
270
 
114
- Style/StringLiterals:
271
+ # Prefer Foo.method over Foo::method
272
+ Style/ColonMethodCall:
115
273
  Enabled: true
116
- EnforcedStyle: double_quotes
117
274
 
118
- Style/StringLiteralsInInterpolation:
275
+ Style/TrivialAccessors:
276
+ Enabled: true
277
+
278
+ # Prefer a = b || c over a = b ? b : c
279
+ Style/RedundantCondition:
280
+ Enabled: true
281
+
282
+ Style/RedundantDoubleSplatHashBraces:
283
+ Enabled: true
284
+
285
+ Style/OpenStructUse:
286
+ Enabled: true
287
+
288
+ Style/ArrayIntersect:
289
+ Enabled: true
290
+
291
+ Style/KeywordArgumentsMerging:
292
+ Enabled: true
293
+
294
+ Performance/BindCall:
295
+ Enabled: true
296
+
297
+ Performance/FlatMap:
298
+ Enabled: true
299
+
300
+ Performance/MapCompact:
119
301
  Enabled: true
120
- EnforcedStyle: double_quotes
121
302
 
122
- Style/SymbolArray:
123
- Enabled: false
303
+ Performance/SelectMap:
304
+ Enabled: true
305
+
306
+ Performance/RedundantMerge:
307
+ Enabled: true
308
+
309
+ Performance/StartWith:
310
+ Enabled: true
124
311
 
125
- Style/WordArray:
126
- Enabled: false
312
+ Performance/EndWith:
313
+ Enabled: true
314
+
315
+ Performance/RegexpMatch:
316
+ Enabled: true
317
+
318
+ Performance/ReverseEach:
319
+ Enabled: true
320
+
321
+ Performance/StringReplacement:
322
+ Enabled: true
323
+
324
+ Performance/DeletePrefix:
325
+ Enabled: true
326
+
327
+ Performance/DeleteSuffix:
328
+ Enabled: true
329
+
330
+ Performance/InefficientHashSearch:
331
+ Enabled: true
332
+
333
+ Performance/ConstantRegexp:
334
+ Enabled: true
335
+
336
+ Performance/RedundantStringChars:
337
+ Enabled: true
338
+
339
+ Performance/StringInclude:
340
+ Enabled: true