struct
Amber::Router::ParamConstraints::CharacterRun
- Amber::Router::ParamConstraints::CharacterRun
- Struct
- Value
- Object
Overview
Matches a segment made only of the given ASCII characters, with a length
between #min_length and #max_length bytes.
hex = CharacterRun.new("hex", '0'..'9', 'a'..'f', 'A'..'F')
hex.matches?("c0ffee") # => true
hex.matches?("coffee") # => false
NUMERIC.with_length(3).matches?("042") # => true
Included Modules
Defined in:
amber/router/param_constraints/character_run.crConstructors
-
.new(label : String, *characters : Char | Range(Char, Char), min_length : Int32 = 1, max_length : Int32 | Nil = nil)
Builds a rule from characters and character ranges.
Instance Method Summary
- #label : String
-
#matches?(segment : String) : Bool
Returns
truewhen segment satisfies this rule. -
#matches_span?(path : String, byte_offset : Int32, bytesize : Int32) : Bool
Returns
truewhen the segment of path that starts at byte_offset and is bytesize bytes long satisfies this rule. - #max_length : Int32 | Nil
- #min_length : Int32
-
#to_s(io : IO) : Nil
Writes the short label that route listings and
Route#to_jsonshow for this rule. -
#with_length(min : Int32, max : Int32 | Nil) : CharacterRun
Returns a copy of this rule that accepts min to max characters; a
nilmax leaves the length unbounded. -
#with_length(length : Int32) : CharacterRun
Returns a copy of this rule that accepts exactly length characters.
Instance methods inherited from module Amber::Router::ParamConstraint
matches?(segment : String) : Bool
matches?,
matches_span?(path : String, byte_offset : Int32, bytesize : Int32) : Bool
matches_span?,
to_s(io : IO) : Nil
to_s
Constructor Detail
Builds a rule from characters and character ranges. Raises
ArgumentError for a character outside ASCII, an empty range, or
lengths that no segment could have.
Instance Method Detail
Returns true when segment satisfies this rule.
Returns true when the segment of path that starts at byte_offset
and is bytesize bytes long satisfies this rule. The router calls this
while it walks a path; the built-in rules override it to read the bytes
in place instead of copying the segment.
Writes the short label that route listings and Route#to_json show for
this rule.
Returns a copy of this rule that accepts min to max characters; a
nil max leaves the length unbounded.
Returns a copy of this rule that accepts exactly length characters.