Class: Engine

Inherits:
Object
  • Object
show all
Defined in:
lib/active_device/engine.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user_agent) ⇒ Engine

Initialize with user agent string.



11
12
13
# File 'lib/active_device/engine.rb', line 11

def initialize user_agent
  @user_agent = user_agent.strip
end

Instance Attribute Details

#user_agentObject (readonly)

User agent string.



6
7
8
# File 'lib/active_device/engine.rb', line 6

def user_agent
  @user_agent
end

Class Method Details

.engine(user_agent) ⇒ Object

Return engine symbol for user agent user_agent.



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/active_device/engine.rb', line 19

def self.engine user_agent
  case user_agent
  when /Webkit/i    ; :Webkit
  when /Khtml/i     ; :khtml
  when /Konqueror/i ; :Konqueror
  when /Presto/i    ; :Presto
  when /Trident/i   ; :Trident
  when /Gecko/i     ; :Gecko
  when /MSIE/i      ; :MSIE
  when /Chrome/i    ; :Chrome
  when /Darwin/i    ; :Darwin
  when /NetFront/i  ; :NetFront
  when /UP.Browser/i; :'UP.Browser'
  when /Palm/i      ; :Palm
  else                :Unknown
  end
end

.engine_version(user_agent) ⇒ Object

Return engine version for user agent user_agent.



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/active_device/engine.rb', line 40

def self.engine_version user_agent
  engine = engine user_agent
  case engine
  when :Webkit;
    if user_agent =~ /#{engine}[\/ ]([\d\w\.\-]+)/i
      $1
    elsif user_agent =~ /#{engine}([0-9\.\-]+)/i
      $1
    end
  when :NetFront;
    if user_agent =~ /#{engine}[\/ ]([\d\w\.\-]+)/i
      $1
    elsif user_agent =~ /#{engine}([0-9\.\-]+)/i
      $1
    end
  when :'UP.Browser';
    if user_agent =~ /#{engine}[\/ ]([\d\w\.\-]+)/i
      $1
    elsif user_agent =~ /#{engine}([0-9\.\-]+)/i
      $1
    end
  else $1 if user_agent =~ /#{engine user_agent}[\/ ]([\d\w\.\-]+)/i
  end
end

.is_engine?(user_agent, engine) ⇒ Boolean

Is string. Device

Returns:

  • (Boolean)


68
69
70
71
72
73
# File 'lib/active_device/engine.rb', line 68

def self.is_engine? user_agent, engine
  engine_sym = engine user_agent
  engine_sym = engine_sym.to_s.downcase
  engine = engine.to_s.downcase
  engine_sym.include? engine
end