agent_orange 0.0.8 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -60,20 +60,20 @@ module AgentOrange
60
60
  return self.platform.name.downcase.include?(name.to_s.downcase)
61
61
  end
62
62
  else
63
- (self.type == "computer")
63
+ (self.type == :computer)
64
64
  end
65
65
  end
66
66
 
67
67
  def is_mobile?(name=nil)
68
- if name
68
+ if !name.nil?
69
69
  case name
70
70
  when String
71
- return self.platform.name.downcase.include?(name.downcase)
71
+ return self.platform.name.downcase.include?(name.downcase) || self.platform.version.downcase.include?(name.downcase)
72
72
  when Symbol
73
- return self.platform.name.downcase.include?(name.to_s.downcase)
73
+ return self.platform.name.downcase.include?(name.to_s.downcase) || self.platform.version.to_s.downcase.include?(name.to_s.downcase)
74
74
  end
75
75
  else
76
- self.type == "mobile"
76
+ (self.type == :mobile)
77
77
  end
78
78
  end
79
79
 
@@ -86,7 +86,7 @@ module AgentOrange
86
86
  return self.name.downcase.include?(name.to_s.downcase)
87
87
  end
88
88
  else
89
- self.type == "bot"
89
+ (self.type == :bot)
90
90
  end
91
91
  end
92
92
 
@@ -6,63 +6,22 @@ module AgentOrange
6
6
 
7
7
  PLATFORMS = {
8
8
  :android => 'android',
9
- :ios => 'iphone|ipad|ipod',
9
+ :apple => 'iphone|ipad|ipod',
10
10
  :mac => 'macintosh',
11
11
  :pc => 'freebsd|linux|netbsd|windows|x11'
12
12
  }
13
13
 
14
14
  PLATFORM_NAMES = {
15
15
  :android => 'Android',
16
- :ios => 'iOS',
16
+ :apple => 'Apple',
17
17
  :mac => 'Macintosh',
18
18
  :pc => 'PC'
19
19
  }
20
-
21
- def old_parse(user_agent)
22
- AgentOrange.debug "PLATFORM PARSING", 2
23
- groups = user_agent.scan(/([^\/[:space:]]*)(\/([^[:space:]]*))?([[:space:]]*\[[a-zA-Z][a-zA-Z]\])?[[:space:]]*(\((([^()]|(\([^()]*\)))*)\))?[[:space:]]*/i)
24
- groups.each_with_index do |pieces,i|
25
- name = pieces[0]
26
- version = pieces[2]
27
- comment = pieces[5]
28
-
29
- if comment =~ /(#{PLATFORMS.collect{|cat,regex| regex}.join(')|(')})/i
30
- # Found the device
31
- AgentOrange.debug " Got a platform in group #{i+1}!", 2
32
- AgentOrange.debug " Raw Name : #{name}", 2
33
- AgentOrange.debug " Raw Version: #{version}", 2
34
- AgentOrange.debug " Raw Comment: #{comment}", 2
35
- AgentOrange.debug "", 2
36
-
37
- # Determine platform type
38
- if comment =~ /(#{PLATFORMS[:android]})/i
39
- self.type = "android"
40
- end
41
- if comment =~ /(#{PLATFORMS[:ios]})/i
42
- self.type = "ios"
43
- end
44
- if comment =~ /(#{PLATFORMS[:mac]})/i
45
- self.type = "mac"
46
- end
47
- if comment =~ /(#{PLATFORMS[:pc]})/i
48
- self.type = "pc"
49
- end
50
-
51
- # Determine platform name
52
- self.name = PLATFORM_NAMES[self.type.to_sym]
53
-
54
- # Determine platform version
55
- self.version = nil
56
- end
57
-
58
- end
59
-
60
- AgentOrange.debug "PLATFORM ANALYSIS", 2
61
- AgentOrange.debug " Type: #{self.type}", 2
62
- AgentOrange.debug " Name: #{self.name}", 2
63
- AgentOrange.debug " Version: #{self.version}", 2
64
- AgentOrange.debug "", 2
65
- end
20
+ PLATFORM_VERSIONS = {
21
+ :ipad => 'ipad',
22
+ :iphone => 'iphone',
23
+ :ipod => 'ipod'
24
+ }
66
25
 
67
26
  def parse(user_agent)
68
27
  AgentOrange.debug "PLATFORM PARSING", 2
@@ -84,7 +43,22 @@ module AgentOrange
84
43
 
85
44
  self.type = self.determine_type(PLATFORMS, content[:comment])
86
45
  self.name = PLATFORM_NAMES[self.type.to_sym]
87
- self.version = nil
46
+
47
+ if self.type == :apple
48
+ self.version = case self.determine_type(PLATFORM_VERSIONS, content[:comment])
49
+ when :ipad
50
+ AgentOrange::Version.new("iPad")
51
+ when :iphone
52
+ AgentOrange::Version.new("iPhone")
53
+ when :ipod
54
+ AgentOrange::Version.new("iPod")
55
+ else
56
+ AgentOrange::Version.new("Unknown")
57
+ end
58
+ else
59
+ self.version = nil
60
+ end
61
+
88
62
  self
89
63
  end
90
64
 
@@ -1,5 +1,5 @@
1
1
  module AgentOrange
2
- VERSION = "0.0.8" # This is for the gem and does not conflict with the rest of the functionality
2
+ VERSION = "0.0.9" # This is for the gem and does not conflict with the rest of the functionality
3
3
 
4
4
  class Version
5
5
  attr_accessor :major, :minor, :patch_level, :build_number
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: agent_orange
3
3
  version: !ruby/object:Gem::Version
4
- hash: 15
4
+ hash: 13
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 8
10
- version: 0.0.8
9
+ - 9
10
+ version: 0.0.9
11
11
  platform: ruby
12
12
  authors:
13
13
  - Kevin Elliott
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-09-12 00:00:00 Z
18
+ date: 2011-09-16 00:00:00 Z
19
19
  dependencies: []
20
20
 
21
21
  description: Parse and process User Agents like a secret one