Class: UAgent::Parser
- Inherits:
-
Object
- Object
- UAgent::Parser
- Defined in:
- lib/uagent.rb
Constant Summary collapse
- @@default_database =
{ :mobile => ['Mobile', 'Opera Mini', 'iPhone', 'ACER', 'Alcatel', 'AUDIOVOX', 'BlackBerry', 'CDM', 'Ericsson', 'LG', 'LGE', 'Motorola', 'MOT', 'NEC', 'Nokia', 'Panasonic', 'QCI', 'SAGEM', 'SAMSUNG', 'SEC', 'Sanyo', 'Sendo', 'SHARP', 'SonyEricsson', 'Telit', 'Telit_mobile_Terminals', 'TSM', 'Palm', 'ViewPad'], :iphone => ['iPhone'], :blackberry => ['BlackBerry'], :android => ['ViewPad7'] }
Instance Attribute Summary collapse
-
#keys ⇒ Object
readonly
Returns the value of attribute keys.
-
#specific_keys ⇒ Object
readonly
Returns the value of attribute specific_keys.
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(*specific_keys) ⇒ Parser
constructor
A new instance of Parser.
- #set_database(database) ⇒ Object
Constructor Details
#initialize(*specific_keys) ⇒ Parser
Returns a new instance of Parser.
20 21 22 23 24 |
# File 'lib/uagent.rb', line 20 def initialize(*specific_keys) @specific_keys = specific_keys.clone @keys = [:desktop, :mobile] + @specific_keys set_database @@default_database end |
Instance Attribute Details
#keys ⇒ Object (readonly)
Returns the value of attribute keys.
7 8 9 |
# File 'lib/uagent.rb', line 7 def keys @keys end |
#specific_keys ⇒ Object (readonly)
Returns the value of attribute specific_keys.
7 8 9 |
# File 'lib/uagent.rb', line 7 def specific_keys @specific_keys end |
Instance Method Details
#call(env) ⇒ Object
33 34 35 36 37 38 39 40 41 |
# File 'lib/uagent.rb', line 33 def call(env) # Check devices in http user agent http_user_agent = env['HTTP_USER_AGENT'] (@specific_keys + [:mobile]).each do |k| return k if @database[k] === http_user_agent end # Device is not found, return the default return :desktop end |
#set_database(database) ⇒ Object
26 27 28 29 30 31 |
# File 'lib/uagent.rb', line 26 def set_database(database) @database = database.clone @database.each do |k,v| @database[k] = Regexp.new( "(" + v.join("|") + ")" ) end end |