Class: Net::HTTP::StructuredFieldValues::Parser
- Inherits:
-
Object
- Object
- Net::HTTP::StructuredFieldValues::Parser
- Defined in:
- lib/net/http/structured_field_values/parser.rb
Overview
RFC8941 compliant parser which parses HTTP fields into Ruby objects.
Defined Under Namespace
Classes: ParseError
Instance Method Summary collapse
-
#initialize(input) ⇒ Parser
constructor
A new instance of Parser.
- #parse_as(type) ⇒ Object
Constructor Details
#initialize(input) ⇒ Parser
Returns a new instance of Parser.
26 27 28 29 30 31 |
# File 'lib/net/http/structured_field_values/parser.rb', line 26 def initialize(input) @scanner = StringScanner.new(input.encode(Encoding::ASCII)) remove_leading_spaces rescue Encoding::UndefinedConversionError raise ParseError, 'Unexpected input' end |
Instance Method Details
#parse_as(type) ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'lib/net/http/structured_field_values/parser.rb', line 35 def parse_as(type) raise ArgumentError, "Invalid type: #{type}" unless TOP_LEVEL_TYPES.include?(type) send(:"parse_as_#{type}").tap do remove_leading_spaces raise ParseError, 'Unexpected input' unless scanner.eos? end end |