agent_orange 0.0.9 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Rakefile CHANGED
@@ -1 +1,3 @@
1
1
  require 'bundler/gem_tasks'
2
+ Dir.glob('./lib/tasks/*.rake').each { |r| import r }
3
+
@@ -14,7 +14,9 @@ user_agent_strings = [
14
14
  "Mozilla/5.0 (Windows NT 6.1; rv:6.0) Gecko/20110814 Firefox/6.0",
15
15
  "Mozilla/5.0 (X11; U; Linux i586; de; rv:5.0) Gecko/20100101 Firefox/5.0",
16
16
  "Opera/9.80 (Windows NT 6.1; U; es-ES) Presto/2.9.181 Version/12.00",
17
- "Opera/9.80 (X11; Linux i686; U; ru) Presto/2.8.131 Version/11.11"
17
+ "Opera/9.80 (X11; Linux i686; U; ru) Presto/2.8.131 Version/11.11",
18
+ "ia_archiver (+http://www.alexa.com/site/help/webmasters; crawler@alexa.com)",
19
+ "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)"
18
20
  ]
19
21
 
20
22
  def process_user_agent(ua_str)
@@ -5,17 +5,17 @@ module AgentOrange
5
5
  class Browser < Base
6
6
  attr_accessor :type, :name, :version
7
7
  attr_accessor :security
8
-
8
+
9
9
  BROWSERS = {
10
10
  :ie => 'MSIE|Internet Explorer|IE',
11
11
  :firefox => 'Firefox',
12
12
  :opera => 'Opera',
13
13
  :safari => 'Safari'
14
14
  }
15
-
15
+
16
16
  def parse(user_agent)
17
17
  AgentOrange.debug "BROWSER PARSING", 2
18
-
18
+
19
19
  groups = parse_user_agent_string_into_groups(user_agent)
20
20
  groups.each_with_index do |content,i|
21
21
  if content[:name] =~ /(#{BROWSERS.collect{|cat,regex| regex}.join(')|(')})/i
@@ -30,32 +30,32 @@ module AgentOrange
30
30
  chosen_content = additional_content
31
31
  end
32
32
  end
33
-
33
+
34
34
  self.populate(chosen_content)
35
35
  end
36
36
  end
37
-
37
+
38
38
  self.analysis
39
39
  end
40
-
40
+
41
41
  def populate(content={})
42
42
  self.debug_raw_content(content)
43
43
  AgentOrange.debug "", 2
44
-
44
+
45
45
  self.type = self.determine_type(BROWSERS, content[:name])
46
46
  self.name = content[:name]
47
47
  self.version = AgentOrange::Version.new(content[:version])
48
48
  self
49
49
  end
50
-
50
+
51
51
  def analysis
52
52
  AgentOrange.debug "BROWSER ANALYSIS", 2
53
53
  self.debug_content(:type => self.type, :name => self.name, :version => self.version)
54
54
  AgentOrange.debug "", 2
55
55
  end
56
-
56
+
57
57
  def to_s
58
58
  [self.name, self.version].compact.join(' ')
59
59
  end
60
60
  end
61
- end
61
+ end
@@ -10,16 +10,16 @@ module AgentOrange
10
10
  attr_accessor :platform
11
11
  attr_accessor :operating_system
12
12
  attr_accessor :engine
13
-
13
+
14
14
  DEVICES = {
15
15
  :computer => 'windows|macintosh|x11|linux',
16
16
  :mobile => 'ipod|ipad|iphone|palm|android|opera mini|hiptop|windows ce|smartphone|mobile|treo|psp',
17
- :bot => 'bot'
17
+ :bot => 'bot|googlebot|crawler|spider|robot|crawling'
18
18
  }
19
-
19
+
20
20
  def parse(user_agent)
21
21
  AgentOrange.debug "DEVICE PARSING", 2
22
-
22
+
23
23
  groups = parse_user_agent_string_into_groups(user_agent)
24
24
  groups.each_with_index do |content,i|
25
25
  if content[:comment] =~ /(#{DEVICES.collect{|cat,regex| regex}.join(')|(')})/i
@@ -27,30 +27,30 @@ module AgentOrange
27
27
  self.populate(content)
28
28
  end
29
29
  end
30
-
30
+
31
31
  self.analysis
32
-
32
+
33
33
  self.platform = AgentOrange::Platform.new(user_agent)
34
34
  self.operating_system = AgentOrange::OperatingSystem.new(user_agent)
35
35
  self.engine = AgentOrange::Engine.new(user_agent)
36
36
  end
37
-
37
+
38
38
  def populate(content={})
39
39
  self.debug_raw_content(content)
40
40
  AgentOrange.debug "", 2
41
-
41
+
42
42
  self.type = self.determine_type(DEVICES, content[:comment])
43
43
  self.name = self.type.to_s.capitalize
44
44
  self.version = nil
45
45
  self
46
46
  end
47
-
47
+
48
48
  def analysis
49
49
  AgentOrange.debug "DEVICE ANALYSIS", 2
50
50
  self.debug_content(:type => self.type, :name => self.name, :version => self.version)
51
51
  AgentOrange.debug "", 2
52
52
  end
53
-
53
+
54
54
  def is_computer?(name=nil)
55
55
  if name
56
56
  case name
@@ -63,9 +63,9 @@ module AgentOrange
63
63
  (self.type == :computer)
64
64
  end
65
65
  end
66
-
66
+
67
67
  def is_mobile?(name=nil)
68
- if !name.nil?
68
+ if !name.nil? && !self.platform.name.nil?
69
69
  case name
70
70
  when String
71
71
  return self.platform.name.downcase.include?(name.downcase) || self.platform.version.downcase.include?(name.downcase)
@@ -76,7 +76,7 @@ module AgentOrange
76
76
  (self.type == :mobile)
77
77
  end
78
78
  end
79
-
79
+
80
80
  def is_bot?(name=nil)
81
81
  if name
82
82
  case name
@@ -89,9 +89,9 @@ module AgentOrange
89
89
  (self.type == :bot)
90
90
  end
91
91
  end
92
-
92
+
93
93
  def to_s
94
94
  [self.name, self.version].compact.join(' ')
95
95
  end
96
96
  end
97
- end
97
+ end
@@ -7,7 +7,7 @@ module AgentOrange
7
7
  class Engine < Base
8
8
  attr_accessor :type, :name, :version
9
9
  attr_accessor :browser
10
-
10
+
11
11
  ENGINES = {
12
12
  :gecko => 'Gecko',
13
13
  :presto => 'Presto',
@@ -15,10 +15,10 @@ module AgentOrange
15
15
  :webkit => 'AppleWebKit',
16
16
  :other => 'Other'
17
17
  }
18
-
18
+
19
19
  def parse(user_agent)
20
20
  AgentOrange.debug "ENGINE PARSING", 2
21
-
21
+
22
22
  groups = parse_user_agent_string_into_groups(user_agent)
23
23
  groups.each_with_index do |content,i|
24
24
  if content[:name] =~ /(#{ENGINES.collect{|cat,regex| regex}.join(')|(')})/i
@@ -33,33 +33,33 @@ module AgentOrange
33
33
  chosen_content = additional_content
34
34
  end
35
35
  end
36
-
36
+
37
37
  self.populate(chosen_content)
38
38
  end
39
39
  end
40
-
40
+
41
41
  self.analysis
42
42
  self.browser = AgentOrange::Browser.new(user_agent)
43
43
  end
44
-
44
+
45
45
  def populate(content={})
46
46
  self.debug_raw_content(content)
47
47
  AgentOrange.debug "", 2
48
-
48
+
49
49
  self.type = self.determine_type(ENGINES, content[:name])
50
50
  self.name = ENGINES[self.type.to_sym]
51
51
  self.version = AgentOrange::Version.new(content[:version])
52
52
  self
53
53
  end
54
-
54
+
55
55
  def analysis
56
56
  AgentOrange.debug "ENGINE ANALYSIS", 2
57
57
  self.debug_content(:type => self.type, :name => self.name, :version => self.version)
58
58
  AgentOrange.debug "", 2
59
59
  end
60
-
60
+
61
61
  def to_s
62
62
  [self.name, self.version].compact.join(' ') || "Unknown"
63
63
  end
64
64
  end
65
- end
65
+ end
@@ -3,7 +3,7 @@ require 'agent_orange/base'
3
3
  module AgentOrange
4
4
  class OperatingSystem < Base
5
5
  attr_accessor :type, :name, :version
6
-
6
+
7
7
  OPERATING_SYSTEMS = {
8
8
  :android => 'android',
9
9
  :freebsd => 'freebsd',
@@ -26,7 +26,7 @@ module AgentOrange
26
26
 
27
27
  def parse(user_agent)
28
28
  AgentOrange.debug "OPERATING SYSTEM PARSING", 2
29
-
29
+
30
30
  groups = parse_user_agent_string_into_groups(user_agent)
31
31
  groups.each_with_index do |content,i|
32
32
  if content[:comment] =~ /(#{OPERATING_SYSTEMS.collect{|cat,regex| regex}.join(')|(')})/i
@@ -38,32 +38,32 @@ module AgentOrange
38
38
  chosen_content = additional_content
39
39
  end
40
40
  end
41
-
41
+
42
42
  self.populate(chosen_content)
43
43
  end
44
44
  end
45
-
45
+
46
46
  self.analysis
47
47
  end
48
-
48
+
49
49
  def populate(content={})
50
50
  self.debug_raw_content(content)
51
51
  AgentOrange.debug "", 2
52
-
52
+
53
53
  self.type = self.determine_type(OPERATING_SYSTEMS, content[:name])
54
54
  self.name = OPERATING_SYSTEM_NAMES[self.type.to_sym]
55
55
  self.version = AgentOrange::Version.new(content[:version])
56
56
  self
57
57
  end
58
-
58
+
59
59
  def analysis
60
60
  AgentOrange.debug "OPERATING SYSTEM ANALYSIS", 2
61
61
  self.debug_content(:type => self.type, :name => self.name, :version => self.version)
62
62
  AgentOrange.debug "", 2
63
63
  end
64
-
64
+
65
65
  def to_s
66
66
  [self.name, self.version].compact.join(' ')
67
67
  end
68
68
  end
69
- end
69
+ end
@@ -10,7 +10,7 @@ module AgentOrange
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
16
  :apple => 'Apple',
@@ -22,10 +22,10 @@ module AgentOrange
22
22
  :iphone => 'iphone',
23
23
  :ipod => 'ipod'
24
24
  }
25
-
25
+
26
26
  def parse(user_agent)
27
27
  AgentOrange.debug "PLATFORM PARSING", 2
28
-
28
+
29
29
  groups = parse_user_agent_string_into_groups(user_agent)
30
30
  groups.each_with_index do |content,i|
31
31
  if content[:comment] =~ /(#{PLATFORMS.collect{|cat,regex| regex}.join(')|(')})/i
@@ -33,17 +33,17 @@ module AgentOrange
33
33
  self.populate(content)
34
34
  end
35
35
  end
36
-
36
+
37
37
  self.analysis
38
38
  end
39
-
39
+
40
40
  def populate(content={})
41
41
  self.debug_raw_content(content)
42
42
  AgentOrange.debug "", 2
43
-
43
+
44
44
  self.type = self.determine_type(PLATFORMS, content[:comment])
45
45
  self.name = PLATFORM_NAMES[self.type.to_sym]
46
-
46
+
47
47
  if self.type == :apple
48
48
  self.version = case self.determine_type(PLATFORM_VERSIONS, content[:comment])
49
49
  when :ipad
@@ -58,18 +58,18 @@ module AgentOrange
58
58
  else
59
59
  self.version = nil
60
60
  end
61
-
61
+
62
62
  self
63
63
  end
64
-
64
+
65
65
  def analysis
66
66
  AgentOrange.debug "PLATFORM ANALYSIS", 2
67
67
  self.debug_content(:type => self.type, :name => self.name, :version => self.version)
68
68
  AgentOrange.debug "", 2
69
69
  end
70
-
70
+
71
71
  def to_s
72
72
  [self.name, self.version].compact.join(' ')
73
73
  end
74
74
  end
75
- end
75
+ end
@@ -3,17 +3,17 @@ require 'agent_orange/device'
3
3
  module AgentOrange
4
4
  DEBUG = false
5
5
  DEBUG_LEVEL = 1
6
-
6
+
7
7
  class UserAgent
8
8
  attr_accessor :user_agent_string
9
9
  attr_accessor :user_language
10
10
  attr_accessor :device
11
-
11
+
12
12
  def initialize(user_agent_string)
13
13
  self.parse(user_agent_string)
14
14
  end
15
15
 
16
- def parse(user_agent)
16
+ def parse(user_agent)
17
17
  self.user_agent_string = user_agent
18
18
  self.device = AgentOrange::Device.new(self.user_agent_string)
19
19
 
@@ -25,7 +25,7 @@ module AgentOrange
25
25
 
26
26
  self.summary
27
27
  end
28
-
28
+
29
29
  def is_computer?(type=nil)
30
30
  self.device.is_computer?(type)
31
31
  end
@@ -39,14 +39,14 @@ module AgentOrange
39
39
  end
40
40
 
41
41
  def to_s
42
- [self.device,
43
- self.device.platform,
44
- self.device.operating_system,
45
- self.device.engine,
42
+ [self.device,
43
+ self.device.platform,
44
+ self.device.operating_system,
45
+ self.device.engine,
46
46
  self.device.engine.browser
47
47
  ].compact.join(", ")
48
48
  end
49
-
49
+
50
50
  def to_human_string
51
51
  if self.device && self.device.engine && self.device.engine.browser
52
52
  "User has a #{self.device} running #{self.device.engine.browser} (which is based on #{self.device.engine})."
@@ -74,9 +74,9 @@ module AgentOrange
74
74
  AgentOrange.debug
75
75
  end
76
76
  end
77
-
77
+
78
78
  def self.debug(str="", level=1)
79
79
  puts str if DEBUG && (DEBUG_LEVEL >= level)
80
80
  end
81
-
82
- end
81
+
82
+ end
@@ -1,6 +1,6 @@
1
1
  module AgentOrange
2
- VERSION = "0.0.9" # This is for the gem and does not conflict with the rest of the functionality
3
-
2
+ VERSION = "0.1.0" # This is for the gem and does not conflict with the rest of the functionality
3
+
4
4
  class Version
5
5
  attr_accessor :major, :minor, :patch_level, :build_number
6
6
 
@@ -13,21 +13,25 @@ module AgentOrange
13
13
 
14
14
  pieces = version_string.split('.')
15
15
  pieces_count = pieces.count
16
-
16
+
17
17
  self.major = pieces[0] if pieces_count >= 1
18
18
  self.minor = pieces[1] if pieces_count >= 2
19
19
  self.patch_level = pieces[2] if pieces_count >= 3
20
20
  self.build_number = pieces[3] if pieces_count >= 4
21
21
  end
22
-
22
+
23
23
  def to_s
24
24
  [self.major, self.minor, self.patch_level, self.build_number].compact.join('.')
25
25
  end
26
-
26
+
27
27
  private
28
-
28
+
29
29
  def sanitize_version_string(version_string)
30
- version_string.gsub('_','.')
30
+ unless version_string.nil?
31
+ version_string.gsub('_','.')
32
+ else
33
+ ""
34
+ end
31
35
  end
32
36
  end
33
- end
37
+ end
data/lib/agent_orange.rb CHANGED
@@ -5,4 +5,4 @@ require 'agent_orange/engine'
5
5
  require 'agent_orange/browser'
6
6
 
7
7
  module AgentOrange
8
- end
8
+ end
metadata CHANGED
@@ -1,40 +1,24 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: agent_orange
3
- version: !ruby/object:Gem::Version
4
- hash: 13
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 0
9
- - 9
10
- version: 0.0.9
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Kevin Elliott
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2011-09-16 00:00:00 Z
12
+ date: 2011-10-21 00:00:00.000000000Z
19
13
  dependencies: []
20
-
21
14
  description: Parse and process User Agents like a secret one
22
- email:
15
+ email:
23
16
  - kevin@welikeinc.com
24
- executables:
17
+ executables:
25
18
  - agent_orange_example
26
19
  extensions: []
27
-
28
20
  extra_rdoc_files: []
29
-
30
- files:
31
- - .gitignore
32
- - Gemfile
33
- - README.rdoc
34
- - Rakefile
35
- - agent_orange.gemspec
36
- - bin/agent_orange_example
37
- - lib/agent_orange.rb
21
+ files:
38
22
  - lib/agent_orange/base.rb
39
23
  - lib/agent_orange/browser.rb
40
24
  - lib/agent_orange/device.rb
@@ -43,38 +27,33 @@ files:
43
27
  - lib/agent_orange/platform.rb
44
28
  - lib/agent_orange/user_agent.rb
45
29
  - lib/agent_orange/version.rb
30
+ - lib/agent_orange.rb
31
+ - bin/agent_orange_example
32
+ - Gemfile
33
+ - Rakefile
34
+ - README.rdoc
46
35
  homepage: http://github.com/kevinelliott/agent_orange
47
36
  licenses: []
48
-
49
37
  post_install_message:
50
38
  rdoc_options: []
51
-
52
- require_paths:
39
+ require_paths:
53
40
  - lib
54
- required_ruby_version: !ruby/object:Gem::Requirement
41
+ required_ruby_version: !ruby/object:Gem::Requirement
55
42
  none: false
56
- requirements:
57
- - - ">="
58
- - !ruby/object:Gem::Version
59
- hash: 3
60
- segments:
61
- - 0
62
- version: "0"
63
- required_rubygems_version: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ required_rubygems_version: !ruby/object:Gem::Requirement
64
48
  none: false
65
- requirements:
66
- - - ">="
67
- - !ruby/object:Gem::Version
68
- hash: 3
69
- segments:
70
- - 0
71
- version: "0"
49
+ requirements:
50
+ - - ! '>='
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
72
53
  requirements: []
73
-
74
54
  rubyforge_project: agent_orange
75
- rubygems_version: 1.8.5
55
+ rubygems_version: 1.8.10
76
56
  signing_key:
77
57
  specification_version: 3
78
58
  summary: Parse and process User Agents like a secret one
79
59
  test_files: []
80
-
data/.gitignore DELETED
@@ -1,4 +0,0 @@
1
- *.gem
2
- .bundle
3
- Gemfile.lock
4
- pkg/*
data/agent_orange.gemspec DELETED
@@ -1,20 +0,0 @@
1
- # -*- encoding: utf-8 -*-
2
- $:.push File.expand_path("../lib", __FILE__)
3
- require "agent_orange/version"
4
-
5
- Gem::Specification.new do |s|
6
- s.name = "agent_orange"
7
- s.version = AgentOrange::VERSION
8
- s.authors = ["Kevin Elliott"]
9
- s.email = ["kevin@welikeinc.com"]
10
- s.homepage = "http://github.com/kevinelliott/agent_orange"
11
- s.summary = %q{Parse and process User Agents like a secret one}
12
- s.description = %q{Parse and process User Agents like a secret one}
13
-
14
- s.rubyforge_project = "agent_orange"
15
-
16
- s.files = `git ls-files`.split("\n")
17
- s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
- s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
- s.require_paths = ["lib"]
20
- end