Class: HTTP::Accept::MediaTypes::MediaRange
- Inherits:
-
Struct
- Object
- Struct
- HTTP::Accept::MediaTypes::MediaRange
- Defined in:
- lib/http/accept/media_types.rb
Instance Attribute Summary collapse
-
#mime_type ⇒ Object
Returns the value of attribute mime_type.
-
#parameters ⇒ Object
Returns the value of attribute parameters.
Class Method Summary collapse
Instance Method Summary collapse
Instance Attribute Details
#mime_type ⇒ Object
Returns the value of attribute mime_type
34 35 36 |
# File 'lib/http/accept/media_types.rb', line 34 def mime_type @mime_type end |
#parameters ⇒ Object
Returns the value of attribute parameters
34 35 36 |
# File 'lib/http/accept/media_types.rb', line 34 def parameters @parameters end |
Class Method Details
.parse(scanner) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/http/accept/media_types.rb', line 39 def self.parse(scanner) return to_enum(:parse, scanner) unless block_given? while mime_type = scanner.scan(MIME_TYPE) parameters = {} while scanner.scan(PARAMETER) key = scanner[:key] if value = scanner[:value] parameters[key] = value elsif quoted_value = scanner[:quoted_value] parameters[key] = QuotedString.new(quoted_value) else raise ParseError.new("Could not parse parameter!") end end yield self.new(mime_type, parameters) # Are there more? return unless scanner.scan(/\s*,\s*/) end raise ParseError.new("Could not parse entire string!") unless scanner.eos? end |
Instance Method Details
#quality_factor ⇒ Object
35 36 37 |
# File 'lib/http/accept/media_types.rb', line 35 def quality_factor parameters.fetch('q', 1.0).to_f end |