Class: HTTP::Accept::Languages::LanguageRange

Inherits:
Struct
  • Object
show all
Defined in:
lib/http/accept/languages.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#localeObject

Returns the value of attribute locale

Returns:

  • (Object)

    the current value of locale



85
86
87
# File 'lib/http/accept/languages.rb', line 85

def locale
  @locale
end

#qObject

Returns the value of attribute q

Returns:

  • (Object)

    the current value of q



85
86
87
# File 'lib/http/accept/languages.rb', line 85

def q
  @q
end

Class Method Details

.parse(scanner) ⇒ Object

Raises:



90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/http/accept/languages.rb', line 90

def self.parse(scanner)
  return to_enum(:parse, scanner) unless block_given?
  
  while scanner.scan(LANGUAGE_RANGE)
    yield self.new(scanner[:locale], scanner[:q])
    
    # Are there more?
    break unless scanner.scan(/\s*,\s*/)
  end
  
  raise ParseError.new("Could not parse entire string!") unless scanner.eos?
end

Instance Method Details

#quality_factorObject



86
87
88
# File 'lib/http/accept/languages.rb', line 86

def quality_factor
  (q || 1.0).to_f
end