Class: Strelka::HTTPRequest::Charset
- Inherits:
-
AcceptParam
- Object
- AcceptParam
- Strelka::HTTPRequest::Charset
- Defined in:
- lib/strelka/httprequest/acceptparams.rb
Overview
A content character-set parameter, such as one you'd find in an Accept-Charset header.
Constant Summary
Constants inherited from AcceptParam
AcceptParam::Q_DEFAULT, AcceptParam::Q_MAX
Instance Attribute Summary
Attributes inherited from AcceptParam
#extensions, #qvalue, #subtype, #type
Class Method Summary collapse
-
.parse(accept_param) ⇒ Object
Parse the given
accept_paramas a charset and return a Strelka::HTTPRequest::Charset object for it.
Instance Method Summary collapse
-
#=~(other) ⇒ Object
Match operator -- returns true if
othermatches the receiving AcceptParam. -
#encoding_object ⇒ Object
Return the Ruby Encoding object that is associated with the parameter's charset.
-
#to_s ⇒ Object
Return the parameter as a String suitable for inclusion in an Accept-language header.
Methods inherited from AcceptParam
#<=>, #extension_strings, #initialize, #inspect, #qvaluestring
Methods included from AbstractClass
extended, included, #inherited, #pure_virtual
Constructor Details
This class inherits a constructor from Strelka::HTTPRequest::AcceptParam
Class Method Details
.parse(accept_param) ⇒ Object
Parse the given accept_param as a charset and return a
Strelka::HTTPRequest::Charset object for it.
326 327 328 329 330 331 |
# File 'lib/strelka/httprequest/acceptparams.rb', line 326 def self::parse( accept_param ) charset, *stuff = accept_param.split( /\s*;\s*/ ) qval, opts = stuff.partition {|par| par =~ /^q\s*=/ } return new( charset, nil, qval.first, *opts ) end |
Instance Method Details
#=~(other) ⇒ Object
Match operator -- returns true if other matches the receiving
AcceptParam.
364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 |
# File 'lib/strelka/httprequest/acceptparams.rb', line 364 def =~( other ) unless other.is_a?( self.class ) other = self.class.parse( other.to_s ) rescue nil return false unless other end # The special value "*", if present in the Accept-Charset field, # matches every character set (including ISO-8859-1) which is not # mentioned elsewhere in the Accept-Charset field. return true if other.name.nil? || self.name.nil? # Same downcased names or different names for the same encoding should match return true if other.name.downcase == self.name.downcase || other.encoding_object == self.encoding_object return false end |
#encoding_object ⇒ Object
Return the Ruby Encoding object that is associated with the parameter's charset.
353 354 355 356 357 358 359 |
# File 'lib/strelka/httprequest/acceptparams.rb', line 353 def encoding_object return ::Encoding.find( self.name ) rescue ArgumentError => err self.log.warn( err. ) # self.log.debug( err.backtrace.join($/) ) return nil end |
#to_s ⇒ Object
Return the parameter as a String suitable for inclusion in an Accept-language header.
343 344 345 346 347 348 349 |
# File 'lib/strelka/httprequest/acceptparams.rb', line 343 def to_s return [ self.name, self.qvaluestring, self.extension_strings, ].compact.join( ';' ) end |