Strelka::HTTPRequest::

Charset

class
Superclass
Strelka::HTTPRequest::AcceptParam

A content character-set parameter, such as one you'd find in an Accept-Charset header.

Public Class Methods

anchor
parse( accept_param )

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

anchor
=~( other )

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
anchor
encoding_object()

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
anchor
to_s()

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