Class: Xenon::LanguageRange

Inherits:
Object
  • Object
show all
Defined in:
lib/xenon/headers/accept_language.rb

Constant Summary collapse

DEFAULT_Q =
1.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(language, q = DEFAULT_Q) ⇒ LanguageRange

Returns a new instance of LanguageRange.



10
11
12
13
# File 'lib/xenon/headers/accept_language.rb', line 10

def initialize(language, q = DEFAULT_Q)
  @language = language
  @q = Float(q) || DEFAULT_Q
end

Instance Attribute Details

#languageObject (readonly)

Returns the value of attribute language.



6
7
8
# File 'lib/xenon/headers/accept_language.rb', line 6

def language
  @language
end

#qObject (readonly)

Returns the value of attribute q.



6
7
8
# File 'lib/xenon/headers/accept_language.rb', line 6

def q
  @q
end

Instance Method Details

#<=>(other) ⇒ Object



15
16
17
# File 'lib/xenon/headers/accept_language.rb', line 15

def <=>(other)
  @q <=> other.q
end

#to_sObject



19
20
21
22
23
# File 'lib/xenon/headers/accept_language.rb', line 19

def to_s
  s = @language.dup
  s << "; q=#{@q}" if @q != DEFAULT_Q
  s
end