defmastership 1.0.18 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (89) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +4 -0
  3. data/.gitlab-ci.yml +42 -1
  4. data/Gemfile +49 -18
  5. data/Guardfile +44 -0
  6. data/LICENSE +1 -1
  7. data/README.adoc +24 -0
  8. data/Rakefile +0 -1
  9. data/bin/defmastership +5 -5
  10. data/config/cucumber.yml +3 -0
  11. data/config/mutant.yml +22 -16
  12. data/config/reek.yml +129 -105
  13. data/config/rubocop.yml +67 -28
  14. data/defmastership.gemspec +8 -6
  15. data/features/changeref.feature +0 -8
  16. data/features/definition_checksum.feature +0 -10
  17. data/features/definition_version.feature +168 -10
  18. data/features/export.feature +23 -18
  19. data/features/modify.feature +1 -5
  20. data/features/rename_included_files.feature +0 -5
  21. data/features/step_definitions/git_steps.rb +19 -0
  22. data/lib/defmastership/batch_modifier.rb +23 -5
  23. data/lib/defmastership/comment_filter.rb +2 -1
  24. data/lib/defmastership/definition.rb +26 -6
  25. data/lib/defmastership/definition_parser.rb +2 -2
  26. data/lib/defmastership/document.rb +45 -33
  27. data/lib/defmastership/export/body_formatter.rb +55 -0
  28. data/lib/defmastership/export/csv/formatter.rb +64 -0
  29. data/lib/defmastership/export/header_formatter.rb +51 -0
  30. data/lib/defmastership/filters.rb +15 -12
  31. data/lib/defmastership/matching_line.rb +3 -2
  32. data/lib/defmastership/modifier/change_ref.rb +117 -0
  33. data/lib/defmastership/modifier/factory.rb +17 -0
  34. data/lib/defmastership/modifier/modifier_common.rb +71 -0
  35. data/lib/defmastership/modifier/rename_included_files.rb +223 -0
  36. data/lib/defmastership/modifier/update_def.rb +72 -0
  37. data/lib/defmastership/modifier/update_def_checksum.rb +17 -0
  38. data/lib/defmastership/modifier/update_def_version.rb +110 -0
  39. data/lib/defmastership/set_join_hack.rb +2 -0
  40. data/lib/defmastership/version.rb +3 -2
  41. data/lib/defmastership.rb +6 -8
  42. data/spec/unit/{def_mastership → defmastership}/batch_modifier_spec.rb +15 -13
  43. data/spec/unit/{def_mastership → defmastership}/definition_parser_spec.rb +1 -1
  44. data/spec/unit/{def_mastership → defmastership}/definition_spec.rb +1 -1
  45. data/spec/unit/{def_mastership → defmastership}/document_spec.rb +57 -57
  46. data/spec/unit/{def_mastership/csv_formatter_body_spec.rb → defmastership/export/body_formatter_spec.rb} +4 -4
  47. data/spec/unit/{def_mastership/csv_formatter_spec.rb → defmastership/export/csv/formatter_spec.rb} +13 -8
  48. data/spec/unit/{def_mastership/csv_formatter_header_spec.rb → defmastership/export/header_formatter_spec.rb} +3 -3
  49. data/spec/unit/{def_mastership → defmastership}/matching_line_spec.rb +1 -1
  50. data/spec/unit/{def_mastership/change_ref_modifier_spec.rb → defmastership/modifier/change_ref_spec.rb} +19 -44
  51. data/spec/unit/defmastership/modifier/factory_spec.rb +45 -0
  52. data/spec/unit/{def_mastership/modifier_spec.rb → defmastership/modifier/modifier_common_spec.rb} +11 -18
  53. data/spec/unit/{def_mastership/rename_included_files_modifier_spec.rb → defmastership/modifier/rename_included_files_spec.rb} +3 -3
  54. data/spec/unit/{def_mastership/update_def_checksum_modifier_spec.rb → defmastership/modifier/update_def_checksum_spec.rb} +10 -10
  55. data/spec/unit/{def_mastership/update_def_modifier_spec.rb → defmastership/modifier/update_def_spec.rb} +22 -18
  56. data/spec/unit/defmastership/modifier/update_def_version_spec.rb +351 -0
  57. data/spec/unit/{def_mastership_spec.rb → defmastership_spec.rb} +2 -2
  58. data/tasks/code_quality.rake +74 -0
  59. data/tasks/documentation.rake +19 -0
  60. data/tasks/package.rake +4 -0
  61. data/tasks/test.rake +6 -21
  62. metadata +96 -51
  63. data/.rubocop.yml +0 -76
  64. data/README.rdoc +0 -6
  65. data/config/devtools.yml +0 -2
  66. data/config/flay.yml +0 -3
  67. data/config/flog.yml +0 -2
  68. data/config/yardstick.yml +0 -2
  69. data/cucumber.yml +0 -2
  70. data/defmastership.rdoc +0 -5
  71. data/lib/defmastership/change_ref_modifier.rb +0 -99
  72. data/lib/defmastership/constants.rb +0 -89
  73. data/lib/defmastership/csv_formatter.rb +0 -53
  74. data/lib/defmastership/csv_formatter_body.rb +0 -46
  75. data/lib/defmastership/csv_formatter_header.rb +0 -41
  76. data/lib/defmastership/modifier.rb +0 -42
  77. data/lib/defmastership/modifier_factory.rb +0 -12
  78. data/lib/defmastership/parsing_state.rb +0 -31
  79. data/lib/defmastership/rename_included_files_modifier.rb +0 -182
  80. data/lib/defmastership/update_def_checksum_modifier.rb +0 -16
  81. data/lib/defmastership/update_def_modifier.rb +0 -49
  82. data/lib/defmastership/update_def_version_modifier.rb +0 -66
  83. data/spec/unit/def_mastership/modifier_factory_spec.rb +0 -37
  84. data/spec/unit/def_mastership/parsing_state_spec.rb +0 -62
  85. data/spec/unit/def_mastership/update_def_version_modifier_spec.rb +0 -159
  86. data/tasks/package.task +0 -9
  87. data/tasks/smelling_code.rake +0 -38
  88. /data/{.rspec → config/rspec} +0 -0
  89. /data/spec/unit/{def_mastership → defmastership}/string_spec.rb +0 -0
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: defmastership
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.18
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jérôme Arbez-Gindre
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-03-09 00:00:00.000000000 Z
11
+ date: 2024-11-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aasm
@@ -38,6 +38,48 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '2'
41
+ - !ruby/object:Gem::Dependency
42
+ name: csv
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3'
55
+ - !ruby/object:Gem::Dependency
56
+ name: defmastership-core
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: 1.1.0
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: 1.1.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: git
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1'
41
83
  - !ruby/object:Gem::Dependency
42
84
  name: gli
43
85
  requirement: !ruby/object:Gem::Requirement
@@ -52,34 +94,41 @@ dependencies:
52
94
  - - "~>"
53
95
  - !ruby/object:Gem::Version
54
96
  version: '2'
97
+ - !ruby/object:Gem::Dependency
98
+ name: ostruct
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
55
111
  description:
56
112
  email: jeromearbezgindre@gmail.com
57
113
  executables:
58
114
  - defmastership
59
115
  extensions: []
60
- extra_rdoc_files:
61
- - README.rdoc
62
- - defmastership.rdoc
116
+ extra_rdoc_files: []
63
117
  files:
64
118
  - ".gitignore"
65
119
  - ".gitlab-ci.yml"
66
- - ".rspec"
67
- - ".rubocop.yml"
68
120
  - Gemfile
121
+ - Guardfile
69
122
  - LICENSE
70
- - README.rdoc
123
+ - README.adoc
71
124
  - Rakefile
72
125
  - bin/defmastership
73
- - config/devtools.yml
74
- - config/flay.yml
75
- - config/flog.yml
126
+ - config/cucumber.yml
76
127
  - config/mutant.yml
77
128
  - config/reek.yml
129
+ - config/rspec
78
130
  - config/rubocop.yml
79
- - config/yardstick.yml
80
- - cucumber.yml
81
131
  - defmastership.gemspec
82
- - defmastership.rdoc
83
132
  - features/changeref.feature
84
133
  - features/definition_checksum.feature
85
134
  - features/definition_version.feature
@@ -88,51 +137,50 @@ files:
88
137
  - features/modify.feature
89
138
  - features/rename_included_files.feature
90
139
  - features/step_definitions/defmastership_steps.rb
140
+ - features/step_definitions/git_steps.rb
91
141
  - features/support/env.rb
92
142
  - lib/defmastership.rb
93
143
  - lib/defmastership/batch_modifier.rb
94
- - lib/defmastership/change_ref_modifier.rb
95
144
  - lib/defmastership/comment_filter.rb
96
- - lib/defmastership/constants.rb
97
- - lib/defmastership/csv_formatter.rb
98
- - lib/defmastership/csv_formatter_body.rb
99
- - lib/defmastership/csv_formatter_header.rb
100
145
  - lib/defmastership/definition.rb
101
146
  - lib/defmastership/definition_parser.rb
102
147
  - lib/defmastership/document.rb
148
+ - lib/defmastership/export/body_formatter.rb
149
+ - lib/defmastership/export/csv/formatter.rb
150
+ - lib/defmastership/export/header_formatter.rb
103
151
  - lib/defmastership/filters.rb
104
152
  - lib/defmastership/matching_line.rb
105
- - lib/defmastership/modifier.rb
106
- - lib/defmastership/modifier_factory.rb
107
- - lib/defmastership/parsing_state.rb
108
- - lib/defmastership/rename_included_files_modifier.rb
153
+ - lib/defmastership/modifier/change_ref.rb
154
+ - lib/defmastership/modifier/factory.rb
155
+ - lib/defmastership/modifier/modifier_common.rb
156
+ - lib/defmastership/modifier/rename_included_files.rb
157
+ - lib/defmastership/modifier/update_def.rb
158
+ - lib/defmastership/modifier/update_def_checksum.rb
159
+ - lib/defmastership/modifier/update_def_version.rb
109
160
  - lib/defmastership/set_join_hack.rb
110
- - lib/defmastership/update_def_checksum_modifier.rb
111
- - lib/defmastership/update_def_modifier.rb
112
- - lib/defmastership/update_def_version_modifier.rb
113
161
  - lib/defmastership/version.rb
114
162
  - spec/spec_helper.rb
115
- - spec/unit/def_mastership/batch_modifier_spec.rb
116
- - spec/unit/def_mastership/change_ref_modifier_spec.rb
117
- - spec/unit/def_mastership/csv_formatter_body_spec.rb
118
- - spec/unit/def_mastership/csv_formatter_header_spec.rb
119
- - spec/unit/def_mastership/csv_formatter_spec.rb
120
- - spec/unit/def_mastership/definition_parser_spec.rb
121
- - spec/unit/def_mastership/definition_spec.rb
122
- - spec/unit/def_mastership/document_spec.rb
123
- - spec/unit/def_mastership/matching_line_spec.rb
124
- - spec/unit/def_mastership/modifier_factory_spec.rb
125
- - spec/unit/def_mastership/modifier_spec.rb
126
- - spec/unit/def_mastership/parsing_state_spec.rb
127
- - spec/unit/def_mastership/rename_included_files_modifier_spec.rb
128
- - spec/unit/def_mastership/string_spec.rb
129
- - spec/unit/def_mastership/update_def_checksum_modifier_spec.rb
130
- - spec/unit/def_mastership/update_def_modifier_spec.rb
131
- - spec/unit/def_mastership/update_def_version_modifier_spec.rb
132
- - spec/unit/def_mastership_spec.rb
163
+ - spec/unit/defmastership/batch_modifier_spec.rb
164
+ - spec/unit/defmastership/definition_parser_spec.rb
165
+ - spec/unit/defmastership/definition_spec.rb
166
+ - spec/unit/defmastership/document_spec.rb
167
+ - spec/unit/defmastership/export/body_formatter_spec.rb
168
+ - spec/unit/defmastership/export/csv/formatter_spec.rb
169
+ - spec/unit/defmastership/export/header_formatter_spec.rb
170
+ - spec/unit/defmastership/matching_line_spec.rb
171
+ - spec/unit/defmastership/modifier/change_ref_spec.rb
172
+ - spec/unit/defmastership/modifier/factory_spec.rb
173
+ - spec/unit/defmastership/modifier/modifier_common_spec.rb
174
+ - spec/unit/defmastership/modifier/rename_included_files_spec.rb
175
+ - spec/unit/defmastership/modifier/update_def_checksum_spec.rb
176
+ - spec/unit/defmastership/modifier/update_def_spec.rb
177
+ - spec/unit/defmastership/modifier/update_def_version_spec.rb
178
+ - spec/unit/defmastership/string_spec.rb
179
+ - spec/unit/defmastership_spec.rb
180
+ - tasks/code_quality.rake
133
181
  - tasks/console.rake
134
- - tasks/package.task
135
- - tasks/smelling_code.rake
182
+ - tasks/documentation.rake
183
+ - tasks/package.rake
136
184
  - tasks/test.rake
137
185
  homepage: https://gitlab.com/jjag/defmastership/
138
186
  licenses:
@@ -140,10 +188,7 @@ licenses:
140
188
  metadata:
141
189
  rubygems_mfa_required: 'true'
142
190
  post_install_message:
143
- rdoc_options:
144
- - "--title defmastership"
145
- - "--main README.rdoc"
146
- - "-ri"
191
+ rdoc_options: []
147
192
  require_paths:
148
193
  - lib
149
194
  - lib
@@ -158,7 +203,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
158
203
  - !ruby/object:Gem::Version
159
204
  version: '0'
160
205
  requirements: []
161
- rubygems_version: 3.5.6
206
+ rubygems_version: 3.5.22
162
207
  signing_key:
163
208
  specification_version: 4
164
209
  summary: Handling of references and definitions with asciidoctor
data/.rubocop.yml DELETED
@@ -1,76 +0,0 @@
1
- # The behavior of RuboCop can be controlled via the .rubocop.yml
2
- # configuration file. It makes it possible to enable/disable
3
- # certain cops (checks) and to alter their behavior if they accept
4
- # any parameters. The file can be placed either in your home
5
- # directory or in some project directory.
6
- #
7
- # RuboCop will start looking for the configuration file in the directory
8
- # where the inspected file is and continue its way up to the root directory.
9
- #
10
- # See https://github.com/rubocop-hq/rubocop/blob/master/manual/configuration.md
11
-
12
- require:
13
- - rubocop-performance
14
- - rubocop-rspec
15
- - rubocop-rake
16
-
17
- AllCops:
18
- TargetRubyVersion: 2.7
19
- EnabledByDefault: true
20
- DisplayCopNames: true
21
-
22
- Style/Copyright:
23
- Enabled: true
24
- Notice: 'Copyright (\(c\) )?202[0-9] Jerome Arbez-Gindre'
25
- AutocorrectNotice: '# Copyright (c) 2023 Jerome Arbez-Gindre'
26
-
27
- Lint/ConstantResolution: # Not available ins rubocop 0.81
28
- Enabled: false
29
-
30
- Style/DocumentationMethod:
31
- Enabled: false
32
-
33
- Style/StringHashKeys :
34
- Enabled: true
35
- Exclude:
36
- - '*.gemspec'
37
- - 'spec/**/*'
38
-
39
- Style/MissingElse:
40
- EnforcedStyle: case
41
-
42
- Metrics/ModuleLength :
43
- Exclude:
44
- - 'spec/**/*'
45
-
46
- Metrics/BlockLength :
47
- Exclude:
48
- - 'spec/**/*'
49
- - '*.gemspec'
50
-
51
- Security/Eval :
52
- Exclude:
53
- - 'Rakefile'
54
-
55
- Style/ConstantVisibility :
56
- Exclude:
57
- # there is one unique explicit constant visibility for all
58
- # constants
59
- - 'lib/defmastership/constants.rb'
60
-
61
- # rubocop-rspec options
62
- RSpec/MessageExpectation :
63
- Enabled: true
64
-
65
- RSpec/FilePath :
66
- Enabled: true
67
-
68
- RSpec/NestedGroups:
69
- Max: 4
70
-
71
- Layout/RedundantLineBreak:
72
- Enabled: false
73
-
74
- Layout/EndOfLine:
75
- EnforcedStyle: lf
76
-
data/README.rdoc DELETED
@@ -1,6 +0,0 @@
1
- = defmastership
2
-
3
- Describe your project here
4
-
5
- :include:defmastership.rdoc
6
-
data/config/devtools.yml DELETED
@@ -1,2 +0,0 @@
1
- ---
2
- unit_test_timeout: 0.2
data/config/flay.yml DELETED
@@ -1,3 +0,0 @@
1
- ---
2
- threshold: 8
3
- total_score: 119
data/config/flog.yml DELETED
@@ -1,2 +0,0 @@
1
- ---
2
- threshold: 13.5
data/config/yardstick.yml DELETED
@@ -1,2 +0,0 @@
1
- ---
2
- threshold: 100
data/cucumber.yml DELETED
@@ -1,2 +0,0 @@
1
- ---
2
- default: --publish --format pretty
data/defmastership.rdoc DELETED
@@ -1,5 +0,0 @@
1
- = defmastership
2
-
3
- Generate this with
4
- defmastership _doc
5
- After you have described your command line interface
@@ -1,99 +0,0 @@
1
- # Copyright (c) 2020 Jerome Arbez-Gindre
2
- # frozen_string_literal: true
3
-
4
- require 'defmastership/constants'
5
- require 'defmastership/modifier'
6
-
7
- module DefMastership
8
- # Change references from temporary to definitive with multiple RefChangers
9
- class ChangeRefModifier
10
- include Modifier
11
-
12
- REGEXP_FROM = {
13
- definition: {
14
- before: DMRegexp::DEF_BEFORE_REF,
15
- after: DMRegexp::DEF_AFTER_REF
16
- },
17
- iref: {
18
- before: DMRegexp::IREF_DEF_BEF,
19
- after: DMRegexp::IREF_DEF_AFT
20
- }
21
- }.freeze
22
-
23
- private_constant :REGEXP_FROM
24
-
25
- def self.replacement_methods
26
- %i[replace_refdef replace_irefs]
27
- end
28
-
29
- def self.default_config
30
- {
31
- from_regexp: '',
32
- to_template: '',
33
- next_ref: 0
34
- }
35
- end
36
-
37
- def initialize(config)
38
- @parsing_state = ParsingState.new
39
-
40
- setup_modifier_module(config)
41
- end
42
-
43
- def replace(method, line)
44
- public_send(:"replace_#{method}", line)
45
- end
46
-
47
- def replace_refdef(line)
48
- if @parsing_state.enabled?(line)
49
- do_replace_refdef(line)
50
- else
51
- line
52
- end
53
- end
54
-
55
- def replace_irefs(line)
56
- changes.reduce(line) do |res_line, (from, to)|
57
- res_line.gsub(Helper.regexp_from(:iref, from)) do
58
- Helper.text_with(Regexp.last_match, to)
59
- end
60
- end
61
- end
62
-
63
- private
64
-
65
- def do_replace_refdef(line)
66
- line.sub(Helper.regexp_from(:definition, from_regexp)) do
67
- replacement_from(Regexp.last_match)
68
- end
69
- end
70
-
71
- def replacement_from(match)
72
- replacement = to_template % hmerge(match)
73
- changes << [match[:from], replacement]
74
- config[:next_ref] += 1
75
- Helper.text_with(match, replacement)
76
- end
77
-
78
- def hmerge(match)
79
- config.merge(match.named_captures.transform_keys(&:to_sym))
80
- end
81
-
82
- # Helper functions
83
- module Helper
84
- def self.regexp_from(const, from)
85
- regexps = REGEXP_FROM.fetch(const)
86
- regexp_str =
87
- "(?<before>#{regexps[:before]})" \
88
- "(?<from>#{from})" \
89
- "#{DMRegexp::DEF_VERSION_AND_CHECKSUM}" \
90
- "(?<after>#{regexps[:after]})"
91
- Regexp.new(regexp_str, Regexp::EXTENDED)
92
- end
93
-
94
- def self.text_with(match, replacement)
95
- match[:before] + replacement + (match[:version_and_checksum] || '') + match[:after]
96
- end
97
- end
98
- end
99
- end
@@ -1,89 +0,0 @@
1
- # Copyright (c) 2020 Jerome Arbez-Gindre
2
- # frozen_string_literal: true
3
-
4
- module DefMastership
5
- # set of regexp of added asciidoctor constructions
6
- # This module smells of :reek:TooManyConstants
7
- module DMRegexp
8
- SINGLE_LINE_COMMENT = %r{^//[^/]}.freeze
9
-
10
- DEF_BEFORE_REF = <<~'BEF'
11
- ^\s*
12
- \[\s*define\s*,
13
- \s*(?<type>[\w:_-]+)\s*,
14
- \s*
15
- BEF
16
-
17
- DEF_AFTER_REF = <<~'AFT'
18
- \s*
19
- (,\s*\[\s*(?<labels>.*?)\s*\])?\s*\]
20
- AFT
21
-
22
- DEF_VERSION_AND_CHECKSUM = '(?<version_and_checksum>' \
23
- '\((?<explicit_version>[^~]+)?(?<explicit_checksum>~[[:alnum:]]+)?\)' \
24
- ')?'
25
-
26
- DEFINITION = Regexp.new(
27
- "#{DEF_BEFORE_REF}(?<reference>[\\w:_-]+)#{DEF_VERSION_AND_CHECKSUM}#{DEF_AFTER_REF}",
28
- Regexp::EXTENDED
29
- )
30
-
31
- VARIABLE_DEF = /^\s*:(?<varname>[\w:_-]+):\s+
32
- (?<value>\S.*\S)\s*$/x.freeze
33
-
34
- VARIABLE_USE = /{(?<varname>[\w:_-]+)}/x.freeze
35
-
36
- EREF_CONFIG = /^\s*:eref-(?<refname>[\w:_-]+)-(?<symb>prefix|url):\s*
37
- \s*(?<value>\S.*\S)\s*/x.freeze
38
- EREF_DEF = /^\s*
39
- defs:eref\[
40
- \s*(?<refname>[\w:_-]+)\s*,
41
- \s*\[\s*(?<extrefs>[^\]]+?)\s*\]\s*\]/x.freeze
42
- BLOCK = /^--\s*$/.freeze
43
-
44
- IREF_DEF_BEF = 'defs:iref\[\s*'
45
- IREF_DEF_AFT = '\s*\]'
46
- IREF_DEF = Regexp.new(
47
- "#{IREF_DEF_BEF}(?<intref>[\\w:_-]+)#{IREF_DEF_AFT}",
48
- Regexp::EXTENDED
49
- )
50
-
51
- ATTR_CONFIG = /\s*:attr-(?<attr>[\w:_-]+)-prefix:
52
- \s+(?<prefix>.+?)\s*$/x.freeze
53
- ATTR_SET = /\s*
54
- defs:attribute\[
55
- \s*(?<attr>[\w:_-]+)\s*,
56
- \s*(?<value>.+?)\s*\]/x.freeze
57
-
58
- EMPTY_LINE = /^\s*$/.freeze
59
-
60
- WHATEVER = //.freeze
61
-
62
- INCLUDE_KEYWORD = '\binclude::'
63
- INCLUDE_PATH = '(?<path>.*/)?'
64
- INCLUDE_FILENAME = '(?<filename>[^\\/]+)'
65
- INCLUDE_OPTIONS = '\[(?<options>[^\]]*)\]'
66
-
67
- INCLUDE = Regexp.new(
68
- INCLUDE_KEYWORD + INCLUDE_PATH + INCLUDE_FILENAME + INCLUDE_OPTIONS,
69
- Regexp::EXTENDED
70
- )
71
-
72
- public_constant :SINGLE_LINE_COMMENT,
73
- :DEF_BEFORE_REF,
74
- :DEF_AFTER_REF,
75
- :DEFINITION,
76
- :VARIABLE_DEF,
77
- :VARIABLE_USE,
78
- :EREF_CONFIG,
79
- :EREF_DEF,
80
- :BLOCK,
81
- :IREF_DEF_BEF,
82
- :IREF_DEF_AFT,
83
- :IREF_DEF,
84
- :ATTR_CONFIG,
85
- :ATTR_SET,
86
- :EMPTY_LINE,
87
- :WHATEVER
88
- end
89
- end
@@ -1,53 +0,0 @@
1
- # Copyright (c) 2020 Jerome Arbez-Gindre
2
- # frozen_string_literal: true
3
-
4
- require('csv')
5
- require('defmastership/csv_formatter_body')
6
- require('defmastership/csv_formatter_header')
7
-
8
- module DefMastership
9
- # to export a CSV file
10
- class CSVFormatter
11
- def initialize(doc, sep)
12
- @doc = doc
13
- @sep = sep
14
- end
15
-
16
- def export_to(output_file)
17
- column_list = build_column_list
18
- CSV.open(output_file, 'w:ISO-8859-1', col_sep: @sep) do |csv|
19
- csv << header(column_list)
20
- export_definitions_in(csv, column_list)
21
- end
22
- end
23
-
24
- private
25
-
26
- def export_definitions_in(csv, column_list)
27
- @doc.definitions.each { |definition| csv << body(definition, column_list) }
28
- end
29
-
30
- def header(column_list)
31
- header_formatter = CSVFormatterHeader.new(@doc)
32
- header_line = column_list.map { |part| header_formatter.public_send(part) }
33
- header_line.flatten
34
- end
35
-
36
- def body(definition, column_list)
37
- body_formatter = CSVFormatterBody.new(@doc, definition)
38
- body_line = column_list.map { |part| body_formatter.public_send(part) }
39
- body_line.flatten
40
- end
41
-
42
- def build_column_list
43
- [
44
- [:wrong_explicit_checksum, @doc.wrong_explicit_checksum?],
45
- [:explicit_version, @doc.explicit_version?],
46
- [:labels, !@doc.labels.empty?],
47
- [:eref, !@doc.eref.empty?],
48
- [:iref, @doc.iref],
49
- [:attributes, !@doc.attributes.empty?]
50
- ].reduce([:fixed]) { |acc, elem| acc + (elem.fetch(1) ? [elem.first] : []) }
51
- end
52
- end
53
- end
@@ -1,46 +0,0 @@
1
- # Copyright (c) 2020 Jerome Arbez-Gindre
2
- # frozen_string_literal: true
3
-
4
- require('csv')
5
-
6
- require('defmastership/set_join_hack')
7
-
8
- module DefMastership
9
- # format lines per definition
10
- class CSVFormatterBody
11
- def initialize(doc, definition)
12
- @doc = doc
13
- @definition = definition
14
- end
15
-
16
- def fixed
17
- [@definition.type, @definition.reference, @definition.value, @definition.sha256_short]
18
- end
19
-
20
- def wrong_explicit_checksum
21
- wrong_explicit_checksum = @definition.wrong_explicit_checksum
22
- wrong_explicit_checksum ? [wrong_explicit_checksum] : ['']
23
- end
24
-
25
- def explicit_version
26
- explicit_version = @definition.explicit_version
27
- explicit_version ? [explicit_version] : ['']
28
- end
29
-
30
- def labels
31
- [@definition.labels.join("\n")]
32
- end
33
-
34
- def eref
35
- @doc.eref.map { |key,| @definition.eref.fetch(key, []).join("\n") }
36
- end
37
-
38
- def iref
39
- [@definition.iref.join("\n")]
40
- end
41
-
42
- def attributes
43
- @doc.attributes.map { |key,| @definition.attributes.fetch(key, '') }
44
- end
45
- end
46
- end
@@ -1,41 +0,0 @@
1
- # Copyright (c) 2020 Jerome Arbez-Gindre
2
- # frozen_string_literal: true
3
-
4
- require('csv')
5
-
6
- module DefMastership
7
- # format header for one document
8
- class CSVFormatterHeader
9
- def initialize(doc)
10
- @doc = doc
11
- end
12
-
13
- def fixed
14
- %w[Type Reference Value Checksum]
15
- end
16
-
17
- def wrong_explicit_checksum
18
- @doc.wrong_explicit_checksum? ? ['Wrong explicit checksum'] : []
19
- end
20
-
21
- def explicit_version
22
- @doc.explicit_version? ? ['Version'] : []
23
- end
24
-
25
- def labels
26
- @doc.labels.empty? ? [] : %w[Labels]
27
- end
28
-
29
- def eref
30
- @doc.eref.map { |_, ref| ref.fetch(:prefix) }
31
- end
32
-
33
- def iref
34
- @doc.iref ? ['Internal links'] : []
35
- end
36
-
37
- def attributes
38
- @doc.attributes.map { |_, value| value }
39
- end
40
- end
41
- end