Class: Model

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user_agent) ⇒ Model

Initialize with user agent user_agent.



10
11
12
# File 'lib/active_device/model.rb', line 10

def initialize user_agent
  @user_agent = user_agent.strip
end

Instance Attribute Details

#user_agentObject (readonly)

User agent user_agent.



5
6
7
# File 'lib/active_device/model.rb', line 5

def user_agent
  @user_agent
end

Class Method Details

.brand_model(user_agent) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/active_device/model.rb', line 14

def self.brand_model user_agent
  case user_agent
  when /iPad/i                        ; :iPad
  when /iPhone/i                      ; :iPhone
  when /SAMSUNG[\w\-\.\_\ ]*/i        ; samsung_models user_agent
  when /Nokia[\w\.\_\ ]*/i            ; nokia_models user_agent
  when /HTC[\w\-\.\_\ ]*/i            ; htc_models user_agent
  when /SonyEricsson[\w\-\.\_\ ]*/i   ; sonyericsson_models user_agent
  when /Opera Mini/i                  ; :'Opera Mini'
  when /Opera Mobi/i                  ; :'Opera Mobile'
  when /Palm/i                        ; palm_models user_agent
  when /webOS/i                       ; palm_models user_agent
  when /T-Mobile G1/i                 ; :'T-Mobile G1'
  when /Dream/i                       ; :'Dream'
  when /^Mozilla[0-9\-\.\_\ ]*/i      ; :Unknown
  else                                ; :"#{user_agent[/[\w\-\.\_]*/i]}"
  end
end

.htc_models(user_agent) ⇒ Object



46
47
48
49
50
51
52
53
54
55
# File 'lib/active_device/model.rb', line 46

def self.htc_models user_agent
  if user_agent =~ /^HTC[\w\-\.\_\ ]*/i
    model = user_agent[/[\w\-\.\_\ ]*/i]
  elsif user_agent =~ /Vodafone[\w\-\.\_\ ]*/i
    model = user_agent[/Vodafone[\w\-\.\_\ ]*/i]
  else
    model = user_agent[/HTC[\w\-\.\_\ ]*/i]
  end
  model_clear model
end

.model_clear(model) ⇒ Object



94
95
96
97
98
99
100
101
102
# File 'lib/active_device/model.rb', line 94

def self.model_clear model
  model = model.to_s
  if model.include?("Profile")
    model =  model.gsub(/Profile[\w\.\_\ ]*/i, "")
  elsif model.include?("Mozilla")
    model =  model.gsub(/Mozilla[\w\.\_\ ]*/i, "")
  end
  :"#{model.chomp("-").strip}"
end

.model_reselution(user_agent) ⇒ Object

Return the model reselution for user agent user_agent.



106
107
108
109
110
111
# File 'lib/active_device/model.rb', line 106

def self.model_reselution user_agent
  case user_agent
  when /([0-9]+x+[0-9]*)/i            ; :"#{user_agent[/([0-9]+x+[0-9]*)/i]}"
  else                                ; :'Not Recognized'
  end
end

.nokia_models(user_agent) ⇒ Object

Return the Nokia model for user agent user_agent. Note: Nokia Models Include “Nokia” Returend Value.



37
38
39
40
41
42
43
44
# File 'lib/active_device/model.rb', line 37

def self.nokia_models user_agent
  if user_agent =~ /^Nokia[\w\.\_\ ]*/i
    model = user_agent[/Nokia[\w\.\_\ ]*/i]
  else
    model = user_agent[/Nokia[\w\.\_\ ]*/i]
  end
  model_clear model
end

.palm_models(user_agent) ⇒ Object



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/active_device/model.rb', line 75

def self.palm_models user_agent
  if user_agent =~ /webOS[\w\.\_\-]*/i
    if user_agent[/Pre[\w\.\_\-]*/i]
      model = :'Palm Pre'
    elsif user_agent[/Pixi[\w\.\_\-]*/i]
      model = :'Palm Pixi'
    else 
      model = user_agent[/[\w\.\_\-]*/i]
    end
  elsif user_agent =~ /PalmOS[\w\.\_\-]*/i
    model = user_agent[/Palm[\.\_\-][\w]*/i]
  elsif user_agent =~ /PalmSource[\w\.\_\-]*/i
    model = user_agent[/Palm[\.\_\-][\w]*/i]
  else
    model = user_agent[/Palm[\w\.\_\-]*/i]
  end
  model_clear model
end

.samsung_models(user_agent) ⇒ Object



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

def self.samsung_models user_agent
  if user_agent =~ /^Samsung[\w\.\_\-]*/i
    model = user_agent[/Samsung[\w\.\_\-]*/i]
  else
    model = user_agent[/Samsung[\w\.\_\-]*/i]
  end
  model_clear model
end

.sonyericsson_models(user_agent) ⇒ Object



57
58
59
60
61
62
63
64
# File 'lib/active_device/model.rb', line 57

def self.sonyericsson_models user_agent
  if user_agent =~ /^SonyEricsson[\w\.\_]*/i
    model = user_agent[/SonyEricsson[\w\.\_]*/i]
  else
    model = user_agent[/SonyEricsson[\w\.\_]*/i]
  end
  model_clear model
end