user_agent_parser 2.1.2 → 2.1.3

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of user_agent_parser might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 066f29cb9f46c928c8dbca73076bdf2e6da63b2c
4
- data.tar.gz: 0a171a4c0efa6c0601a4844a68f49bf1316f18d6
3
+ metadata.gz: a721f503d9e59cd7813d9c18db733ef6ecb24c5e
4
+ data.tar.gz: 7acb12c8b075c1f2cae73b8e3ce29023e5bae740
5
5
  SHA512:
6
- metadata.gz: 2636ff74bef1fcef2c8be5070d97fdd0a70c969faafc76106531bf8986fa8336ca744cabe0babf5d6198d1455a3b25e04246abac9a1afb77b16dc5d79890d9dc
7
- data.tar.gz: 06836d83ae49433ffdace34ebcf8f838768e7f533228ba4f48e662e5968744f7a0c29c4c9c64b60e7c9c196fd286f649e9ff577b25dc096065368235666b5059
6
+ metadata.gz: d929dfb2af11c55a29a51cb81ae1a3210327275aed9c45c4055374d95d7d1957d6a446ec6cb3c78b9db90911ca7a041d66ca03ecae9e72a0fa423267005d1bc6
7
+ data.tar.gz: 482194e192ffaac970357316d7ee7976b1add1c18d922de35210d82018d4b3dd003723072abb6f37556c24011a72f20b2cb1820c5af06cad7ec71696485eee01
@@ -0,0 +1,56 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $: << File.expand_path('../../lib', File.readlink(__FILE__))
4
+
5
+ require 'optparse'
6
+
7
+ require 'user_agent_parser'
8
+ require 'user_agent_parser/cli'
9
+
10
+ options = {}
11
+
12
+ optparse = OptionParser.new do|opts|
13
+ opts.on('--name', 'Print name only') do
14
+ options[:name] = true
15
+ end
16
+
17
+ opts.on('--version', 'Print version only') do
18
+ options[:version] = true
19
+ end
20
+
21
+ opts.on('--major', 'Print major version only') do
22
+ options[:major] = true
23
+ end
24
+
25
+ opts.on('--minor', 'Print minor version only') do
26
+ options[:minor] = true
27
+ end
28
+
29
+ opts.on('--os', 'Print operating system only') do
30
+ options[:os] = true
31
+ end
32
+
33
+ opts.on('--format format',
34
+ 'Print output in specified format. The available formatters are:',
35
+ ' - %n: name',
36
+ ' - %v: version',
37
+ ' - %M: major version',
38
+ ' - %m: minor version',
39
+ ' - %o: operating system'
40
+ ) do |format|
41
+ options[:format] = format
42
+ end
43
+
44
+ opts.on('-h', '--help', 'Display this screen') do
45
+ puts opts
46
+ exit
47
+ end
48
+ end
49
+
50
+ optparse.parse!
51
+
52
+ parser = UserAgentParser::Parser.new
53
+
54
+ ARGF.each do |line|
55
+ puts UserAgentParser::Cli.new(parser.parse(line), options).run!
56
+ end
@@ -0,0 +1,54 @@
1
+ module UserAgentParser
2
+ class Cli
3
+ def initialize(user_agent, options = {})
4
+ @user_agent = user_agent
5
+ @options = options
6
+ end
7
+
8
+ def run!
9
+ if @options[:name]
10
+ @user_agent.name
11
+ elsif @options[:version]
12
+ with_version do |version|
13
+ version.to_s
14
+ end
15
+ elsif @options[:major]
16
+ major
17
+ elsif @options[:minor]
18
+ minor
19
+ elsif @options[:os]
20
+ @user_agent.os.to_s
21
+ elsif format = @options[:format]
22
+ format.gsub('%n', @user_agent.name).
23
+ gsub('%v', version.to_s).
24
+ gsub('%M', major.to_s).
25
+ gsub('%m', minor.to_s).
26
+ gsub('%o', @user_agent.os.to_s)
27
+ else
28
+ @user_agent.to_s
29
+ end
30
+ end
31
+
32
+ private
33
+
34
+ def major
35
+ with_version do |version|
36
+ version.major
37
+ end
38
+ end
39
+
40
+ def minor
41
+ with_version do |version|
42
+ version.minor
43
+ end
44
+ end
45
+
46
+ def version
47
+ @version ||= @user_agent.version
48
+ end
49
+
50
+ def with_version(&block)
51
+ block.call(version) if version
52
+ end
53
+ end
54
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: user_agent_parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.2
4
+ version: 2.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tim Lucas
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-30 00:00:00.000000000 Z
11
+ date: 2014-03-13 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A simple, comprehensive Ruby gem for parsing user agent strings with
14
14
  the help of BrowserScope's UA database
@@ -19,7 +19,9 @@ extra_rdoc_files: []
19
19
  files:
20
20
  - MIT-LICENSE
21
21
  - Readme.md
22
+ - bin/user_agent_parser
22
23
  - lib/user_agent_parser.rb
24
+ - lib/user_agent_parser/cli.rb
23
25
  - lib/user_agent_parser/device.rb
24
26
  - lib/user_agent_parser/operating_system.rb
25
27
  - lib/user_agent_parser/parser.rb
@@ -46,7 +48,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
46
48
  version: '0'
47
49
  requirements: []
48
50
  rubyforge_project:
49
- rubygems_version: 2.2.1
51
+ rubygems_version: 2.2.2
50
52
  signing_key:
51
53
  specification_version: 4
52
54
  summary: A simple, comprehensive Ruby gem for parsing user agent strings with the