Class: SoberSwag::Reporting::Input::Pattern
- Defined in:
- lib/sober_swag/reporting/input/pattern.rb
Overview
Input values that validate against a pattern
Instance Attribute Summary collapse
-
#input ⇒ #call
readonly
Input type.
-
#pattern ⇒ #matches
readonly
Regexp matcher.
Instance Method Summary collapse
- #call(value) ⇒ Object
-
#formatted_pattern ⇒ Object
Try to format a pattern so it'll work nicely with JS.
-
#initialize(input, pattern) ⇒ Pattern
constructor
A new instance of Pattern.
- #swagger_schema ⇒ Object
Methods included from Interface
#add_schema_key, #call!, #described, #enum, #format, #in_range, #list, #mapped, #modify_schema, #multiple_of, #optional, #or, #referenced, #swagger_path_schema, #swagger_query_schema, #|
Constructor Details
#initialize(input, pattern) ⇒ Pattern
Returns a new instance of Pattern.
7 8 9 10 |
# File 'lib/sober_swag/reporting/input/pattern.rb', line 7 def initialize(input, pattern) @input = input @pattern = pattern end |
Instance Attribute Details
#input ⇒ #call (readonly)
Returns input type.
14 15 16 |
# File 'lib/sober_swag/reporting/input/pattern.rb', line 14 def input @input end |
#pattern ⇒ #matches (readonly)
Returns regexp matcher.
18 19 20 |
# File 'lib/sober_swag/reporting/input/pattern.rb', line 18 def pattern @pattern end |
Instance Method Details
#call(value) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/sober_swag/reporting/input/pattern.rb', line 20 def call(value) val = input.call(value) return val if val.is_a?(Report::Base) if pattern.match?(value) value else Report::Value.new(["did not match pattern #{pattern}"]) end end |
#formatted_pattern ⇒ Object
Try to format a pattern so it'll work nicely with JS.
40 41 42 |
# File 'lib/sober_swag/reporting/input/pattern.rb', line 40 def formatted_pattern pattern.to_s.gsub('?-mix:', '') end |
#swagger_schema ⇒ Object
32 33 34 35 36 |
# File 'lib/sober_swag/reporting/input/pattern.rb', line 32 def swagger_schema single, found = input.swagger_schema [add_schema_key(single, { pattern: formatted_pattern }), found] end |