Class: HTTP::Accept::Languages::LanguageRange
- Inherits:
-
Struct
- Object
- Struct
- HTTP::Accept::Languages::LanguageRange
- Defined in:
- lib/http/accept/languages.rb
Instance Attribute Summary collapse
-
#locale ⇒ Object
Returns the value of attribute locale.
-
#q ⇒ Object
Returns the value of attribute q.
Class Method Summary collapse
Instance Method Summary collapse
-
#prefix_of?(other) ⇒ Boolean
If the user ask for ‘en’, this satisfies any language that begins with ‘en-’.
- #quality_factor ⇒ Object
Instance Attribute Details
#locale ⇒ Object
Returns the value of attribute locale
36 37 38 |
# File 'lib/http/accept/languages.rb', line 36 def locale @locale end |
#q ⇒ Object
Returns the value of attribute q
36 37 38 |
# File 'lib/http/accept/languages.rb', line 36 def q @q end |
Class Method Details
.parse(scanner) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/http/accept/languages.rb', line 41 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? return unless scanner.scan(/\s*,\s*/) end raise ParseError.new("Could not parse entire string!") unless scanner.eos? end |
Instance Method Details
#prefix_of?(other) ⇒ Boolean
If the user ask for ‘en’, this satisfies any language that begins with ‘en-’
55 56 57 |
# File 'lib/http/accept/languages.rb', line 55 def prefix_of? other other.start_with(locale) end |
#quality_factor ⇒ Object
37 38 39 |
# File 'lib/http/accept/languages.rb', line 37 def quality_factor (q || 1.0).to_f end |