class Strelka::HTTPRequest::Charset
A content character-set parameter, such as one you'd find in an Accept-Charset
header.
Public Class Methods
parse( accept_param )
click to toggle source
Parse the given accept_param
as a charset and return a Strelka::HTTPRequest::Charset
object for it.
# File lib/strelka/httprequest/acceptparams.rb, line 325 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
Public Instance Methods
=~( other )
click to toggle source
Match operator – returns true if other
matches the receiving AcceptParam
.
# File lib/strelka/httprequest/acceptparams.rb, line 363 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()
click to toggle source
Return the Ruby Encoding
object that is associated with the parameter's charset.
# File lib/strelka/httprequest/acceptparams.rb, line 352 def encoding_object return ::Encoding.find( self.name ) rescue ArgumentError => err self.log.warn( err.message ) # self.log.debug( err.backtrace.join($/) ) return nil end
to_s()
click to toggle source
Return the parameter as a String suitable for inclusion in an Accept-language header.
# File lib/strelka/httprequest/acceptparams.rb, line 342 def to_s return [ self.name, self.qvaluestring, self.extension_strings, ].compact.join( ';' ) end