dsv7-parser 7.0.1 → 7.0.2

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.
@@ -1,17 +1,22 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Date and time datatype checks.
4
- #
5
- # Enforces textual formats before validating value ranges:
6
- # - Datum: TT.MM.JJJJ (validated via Date.strptime)
7
- # - Uhrzeit: HH:MM (0..23, 0..59)
8
- # - Zeit: HH:MM:SS,hh (0..23, 0..59, 0..59, 0..99)
9
-
10
3
  require 'date'
11
4
 
12
5
  module Dsv7
13
6
  class Validator
7
+ ##
8
+ # Date and time datatype checks.
9
+ #
10
+ # Enforces textual formats before validating value ranges:
11
+ # - Datum: TT.MM.JJJJ (validated via Date.strptime)
12
+ # - Uhrzeit: HH:MM (0..23, 0..59)
13
+ # - Zeit: HH:MM:SS,hh (0..23, 0..59, 0..59, 0..99)
14
+ #
15
+ # @see specification/dsv7/dsv7_specification.md Date/time formats
16
+ # @api private
14
17
  module WkTypeChecksDateTime
18
+ private
19
+
15
20
  def check_datum(name, idx, val, line_number, _opts = nil)
16
21
  return add_error(datum_format_error(name, idx, val, line_number)) unless
17
22
  val.match?(/^\d{2}\.\d{2}\.\d{4}$/)
@@ -1,13 +1,18 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Enum/group checks (part 1): Bahnlänge, Zeitmessung, Land, etc.
4
- #
5
- # These normalize expectations found in the spec and examples and produce
6
- # actionable error messages that include allowed values.
7
-
8
3
  module Dsv7
9
4
  class Validator
5
+ ##
6
+ # Enum/group checks (part 1): Bahnlänge, Zeitmessung, Land, etc.
7
+ #
8
+ # These normalize expectations found in the spec and examples and produce
9
+ # actionable error messages that include allowed values.
10
+ #
11
+ # @see specification/dsv7/dsv7_specification.md Enumerations overview
12
+ # @api private
10
13
  module WkTypeChecksEnums1
14
+ private
15
+
11
16
  def check_bahnl(name, idx, val, line_number, _opts = nil)
12
17
  allowed = %w[16 20 25 33 50 FW X]
13
18
  return if allowed.include?(val)
@@ -1,13 +1,18 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Enum/group checks (part 2): Technik, Ausübung, Geschlecht, Wertungstyp,
4
- # JG/AK, Meldegeldtypen, Reaktionsart, Nachtragskennzeichen, u. a.
5
- #
6
- # Keep allowed lists centralized here for clarity and reuse across schemas.
7
-
8
3
  module Dsv7
9
4
  class Validator
5
+ ##
6
+ # Enum/group checks (part 2): Technik, Ausübung, Geschlecht, Wertungstyp,
7
+ # JG/AK, Meldegeldtypen, Reaktionsart, Nachtragskennzeichen, u. a.
8
+ #
9
+ # Keep allowed lists centralized here for clarity and reuse across schemas.
10
+ #
11
+ # @see specification/dsv7/dsv7_specification.md Enumerations overview
12
+ # @api private
10
13
  module WkTypeChecksEnums2
14
+ private
15
+
11
16
  def check_technik(name, idx, val, line_number, _opts = nil)
12
17
  return if %w[F R B S L X].include?(val)
13
18
 
@@ -1,11 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Aggregates type‑check mixins used by schemas.
4
- #
5
- # Each `check_<type>(name, index, value, line_number, opts)` method is
6
- # expected to either accept the value or call `add_error(message)` on the
7
- # including schema to record a validation error with context.
8
-
9
3
  require_relative 'types/common'
10
4
  require_relative 'types/datetime'
11
5
  require_relative 'types/enums1'
@@ -13,6 +7,14 @@ require_relative 'types/enums2'
13
7
 
14
8
  module Dsv7
15
9
  class Validator
10
+ ##
11
+ # Aggregates type‑check mixins used by schemas.
12
+ #
13
+ # Each `check_<type>(name, index, value, line_number, opts)` method is
14
+ # expected to either accept the value or call `add_error(message)` on the
15
+ # including schema to record a validation error with context.
16
+ #
17
+ # @api private
16
18
  module WkTypeChecks
17
19
  include WkTypeChecksCommon
18
20
  include WkTypeChecksDateTime
@@ -1,46 +1,43 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Dsv7::Validator
4
- #
5
- # Validates DSV7 files (German Swimming Federation “Format 7”) against a
6
- # pragmatic subset of the official specification. The validator focuses on
7
- # high‑level envelope rules (FORMAT/DATEIENDE, encoding, comments, delimiters),
8
- # filename hints, element cardinalities, and per‑element attribute types for all
9
- # four supported list types (WKDL, VML, ERG, VRL).
10
- #
11
- # Intent
12
- # - Provide fast, streaming validation without external dependencies.
13
- # - Produce precise, stable error and warning messages suitable for tooling and
14
- # tests (see `test/dsv7/*`).
15
- # - Keep responsibilities narrow: structural checks here; parsing in
16
- # `Dsv7::Parser`.
17
- #
18
- # Public API
19
- # - `.validate(input) -> Dsv7::Validator::Result`
20
- # Accepts a file path String, an IO, or a content String (streamed via
21
- # StringIO). Always returns a `Result` object with `errors`, `warnings`,
22
- # `list_type`, `version`, and `valid?`.
23
- #
24
- # Examples
25
- # result = Dsv7::Validator.validate('2024-01-01-Example-Wk.DSV7')
26
- # result.valid? # => true/false
27
- # result.errors # => ["..."]
28
- # result.warnings # => ["..."]
29
- # result.list_type # => 'Wettkampfdefinitionsliste' (after FORMAT)
30
- # result.version # => '7'
31
- #
32
- # Writing good docs for new checks
33
- # - State the rule’s purpose and scope (what it enforces, and why).
34
- # - Describe inputs/outputs and when an error vs. warning is emitted.
35
- # - Keep messages actionable and stable; include line numbers where helpful.
36
- # - Reference spec sections or examples in commit messages or tests.
37
- # - Add both accept and reject tests under `test/dsv7/`.
38
-
39
3
  require 'stringio'
40
4
  require_relative 'validator/result'
41
5
  require_relative 'validator/core'
42
6
 
43
7
  module Dsv7
8
+ ##
9
+ # Dsv7::Validator
10
+ #
11
+ # Validates DSV7 files (German Swimming Federation “Format 7”) against a
12
+ # pragmatic subset of the official specification. The validator focuses on
13
+ # high‑level envelope rules (FORMAT/DATEIENDE, encoding, comments, delimiters),
14
+ # filename hints, element cardinalities, and per‑element attribute types for all
15
+ # four supported list types (WKDL, VML, ERG, VRL).
16
+ #
17
+ # Intent
18
+ # - Provide fast, streaming validation without external dependencies.
19
+ # - Produce precise, stable error and warning messages suitable for tooling and
20
+ # tests (see `test/dsv7/*`).
21
+ # - Keep responsibilities narrow: structural checks here; parsing in
22
+ # {Dsv7::Parser}.
23
+ #
24
+ # Semantics
25
+ # - Errors on UTF‑8 BOM and on invalid UTF‑8 (input is scrubbed for messages).
26
+ # - Warns once when CRLF line endings are detected (still valid).
27
+ # - When validating a file path, may add a filename pattern warning if it
28
+ # does not match `JJJJ-MM-TT-Ort-Zusatz.DSV7`.
29
+ #
30
+ # @api public
31
+ # @since 7.0.0
32
+ # @example Validate a file by path
33
+ # result = Dsv7::Validator.validate('2024-01-01-Example-Wk.DSV7')
34
+ # result.valid? # => true/false
35
+ # result.errors # => ["..."]
36
+ # result.warnings # => ["..."]
37
+ # result.list_type # => 'Wettkampfdefinitionsliste' (after FORMAT)
38
+ # result.version # => '7'
39
+ #
40
+ # @see Dsv7::Parser For streaming parsing helpers and event API
44
41
  # Validates overall conformity of a DSV7 file against high-level rules
45
42
  # extracted from the specification markdown under `specification/dsv7`.
46
43
  #
@@ -48,6 +45,7 @@ module Dsv7
48
45
  # knowledge of the full element schemas.
49
46
  class Validator
50
47
  # Known list types from the overview section
48
+ # @return [Array<String>]
51
49
  ALLOWED_LIST_TYPES = %w[
52
50
  Wettkampfdefinitionsliste
53
51
  Vereinsmeldeliste
@@ -55,10 +53,18 @@ module Dsv7
55
53
  Vereinsergebnisliste
56
54
  ].freeze
57
55
 
58
- # Single public entrypoint. Accepts:
59
- # - IO-like objects (respond_to?(:read)) → streamed
56
+ # Validate a DSV7 input.
57
+ #
58
+ # Accepts:
59
+ # - IO-like objects (`respond_to?(:read)`) → streamed
60
60
  # - String paths to files → streamed
61
61
  # - String content → streamed via StringIO
62
+ #
63
+ # @param input [IO, String] An IO, a file path String, or a String with file content
64
+ # @api public
65
+ # @since 7.0.0
66
+ # @return [Dsv7::Validator::Result] Validation result with errors/warnings and metadata
67
+ # @raise [ArgumentError] if an unsupported input type is provided
62
68
  def self.validate(input)
63
69
  return new.send(:validate_stream, input) if input.respond_to?(:read)
64
70
  return validate_path(input) if input.is_a?(String) && File.file?(input)
@@ -70,6 +76,7 @@ module Dsv7
70
76
  class << self
71
77
  private
72
78
 
79
+ # @api private
73
80
  def validate_path(path)
74
81
  File.open(path, 'rb') do |io|
75
82
  return new.send(:validate_stream, io, filename: File.basename(path))
@@ -79,6 +86,10 @@ module Dsv7
79
86
 
80
87
  private
81
88
 
89
+ # @api private
90
+ # @param io [IO]
91
+ # @param filename [String, nil]
92
+ # @return [Dsv7::Validator::Result]
82
93
  def validate_stream(io, filename: nil)
83
94
  result = Result.new
84
95
  Core.new(result, filename).call_io(io)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dsv7-parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 7.0.1
4
+ version: 7.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - bigcurl
@@ -21,6 +21,7 @@ files:
21
21
  - ".gitignore"
22
22
  - ".rubocop.yml"
23
23
  - ".ruby-version"
24
+ - ".yardopts"
24
25
  - AGENTS.md
25
26
  - Gemfile
26
27
  - Gemfile.lock