Class: Browser::AcceptLanguage
- Inherits:
-
Object
- Object
- Browser::AcceptLanguage
- Defined in:
- lib/browser/accept_language.rb
Instance Attribute Summary collapse
-
#part ⇒ Object
readonly
Returns the value of attribute part.
Class Method Summary collapse
Instance Method Summary collapse
- #code ⇒ Object
- #full ⇒ Object
-
#initialize(part) ⇒ AcceptLanguage
constructor
A new instance of AcceptLanguage.
- #name ⇒ Object
- #quality ⇒ Object
- #region ⇒ Object
Constructor Details
#initialize(part) ⇒ AcceptLanguage
Returns a new instance of AcceptLanguage.
23 24 25 |
# File 'lib/browser/accept_language.rb', line 23 def initialize(part) @part = part end |
Instance Attribute Details
#part ⇒ Object (readonly)
Returns the value of attribute part.
21 22 23 |
# File 'lib/browser/accept_language.rb', line 21 def part @part end |
Class Method Details
.languages ⇒ Object
5 6 7 |
# File 'lib/browser/accept_language.rb', line 5 def self.languages @languages ||= YAML.load_file(Browser.root.join("languages.yml")) end |
.parse(accept_language) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/browser/accept_language.rb', line 9 def self.parse(accept_language) return [] unless accept_language accept_language .split(",") .map {|string| string.squeeze(" ").strip } .map {|part| new(part) } .reject {|al| al.quality.zero? } .sort_by(&:quality) .reverse end |
Instance Method Details
#code ⇒ Object
35 36 37 38 39 40 |
# File 'lib/browser/accept_language.rb', line 35 def code @code ||= begin code = part[/\A([^-;]+)/, 1] code.downcase if code end end |
#full ⇒ Object
27 28 29 |
# File 'lib/browser/accept_language.rb', line 27 def full @full ||= [code, region].compact.join("-") end |
#name ⇒ Object
31 32 33 |
# File 'lib/browser/accept_language.rb', line 31 def name self.class.languages[full] || self.class.languages[code] end |
#quality ⇒ Object
49 50 51 |
# File 'lib/browser/accept_language.rb', line 49 def quality @quality ||= Float(quality_value || 1.0) end |
#region ⇒ Object
42 43 44 45 46 47 |
# File 'lib/browser/accept_language.rb', line 42 def region @region ||= begin region = part[/\A(?:.*?)-([^;-]+)/, 1] region.upcase if region end end |