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
85 86 87 |
# File 'lib/http/accept/media_types.rb', line 85 def mime_type @mime_type end |
#parameters ⇒ Object
Returns the value of attribute parameters
85 86 87 |
# File 'lib/http/accept/media_types.rb', line 85 def parameters @parameters end |
Class Method Details
.parse(scanner, normalize_whitespace = true) ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/http/accept/media_types.rb', line 94 def self.parse(scanner, normalize_whitespace = true) return to_enum(:parse, scanner, normalize_whitespace) 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.unquote(quoted_value, normalize_whitespace) 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
86 87 88 |
# File 'lib/http/accept/media_types.rb', line 86 def quality_factor parameters.fetch('q', 1.0).to_f end |
#split ⇒ Object
90 91 92 |
# File 'lib/http/accept/media_types.rb', line 90 def split @type, @subtype = mime_type.split('/') end |