woothee 0.3.4 → 0.3.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 09b0e8a02cd881ceac57d76d909c60037a27fbfd
4
- data.tar.gz: 1f85b6347a45c3d5ecf630fa7752e5f2dd9b31d4
3
+ metadata.gz: 4f4e1e5a42b49a4f260eb1f1c589bc0c965b10c9
4
+ data.tar.gz: d39f942398a99af4a50e47349158c5423a5806c6
5
5
  SHA512:
6
- metadata.gz: 8cda7085ef3464be2cd9eb540bc9e92e40a6b800fa302a59e84b52817d64e0829d21ac5e5c65086e03779d6cf1044e4e15596c61e1c5e7750e1df8612685ae02
7
- data.tar.gz: daa17937da05ce2f9b5e8c25e3e0f37921bf0a435382d24ed5a26456c9d270f135ffb64e12713f945f2020dd21a57ecff5fba1d0c9a27442fd25b0d3f46e8e90
6
+ metadata.gz: 0a68ca9a4eea76d86486dbe85e8c3394761d2b8ee4c20b9cbf714b4656f108749f52c3b4b7a8cbffbfbfc75e5d7cbb1f18967cd55441db20dd4efe1300d6ba7f
7
+ data.tar.gz: fc9891b07bbac7a96b259418e96b98d1dae2b9a264b573404067597429cb4fc1e8bbf7794334827faeac652f46534f6836b811045a3a50e1e20a2de644b6236f
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.gitmodules ADDED
@@ -0,0 +1,3 @@
1
+ [submodule "woothee"]
2
+ path = woothee
3
+ url = https://github.com/woothee/woothee.git
data/.travis.yml ADDED
@@ -0,0 +1,11 @@
1
+ language: ruby
2
+ rvm:
3
+ - "1.9"
4
+ - "2.0"
5
+ - "jruby-19mode"
6
+ before_script:
7
+ - git submodule update --init
8
+ - bundle install
9
+ - bundle update
10
+ script:
11
+ - make
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 TAGOMORI Satoshi
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Makefile CHANGED
@@ -1,13 +1,11 @@
1
1
  all: test
2
2
 
3
- TIMESTAMP=$(shell date +%Y%m%d-%H%M%S)
3
+ testsets:
4
+ git submodule update --init
4
5
 
5
- checkyaml:
6
- perl ../bin/dataset_checker.pl
7
-
8
- lib/woothee/dataset.rb: ../dataset.yaml
9
- ruby ../bin/dataset_yaml2rb.rb
6
+ lib/woothee/dataset.rb: testsets
7
+ ruby scripts/dataset_yaml2rb.rb
10
8
  sync; sync; sync
11
9
 
12
10
  test: lib/woothee/dataset.rb
13
- rspec spec
11
+ bundle exec rspec spec
data/README.md ADDED
@@ -0,0 +1,79 @@
1
+ # Woothee ruby
2
+
3
+ The Ruby implementation of Project Woothee, which is multi-language user-agent strings parsers.
4
+
5
+ https://github.com/woothee/woothee
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'woothee'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install woothee
20
+
21
+ ## Usage
22
+
23
+ Class 'Woothee' have no instance methods.
24
+
25
+ ### Parsing user-agent
26
+
27
+ ```ruby
28
+ require 'woothee'
29
+ Woothee.parse("Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0)")
30
+ # => {:name=>"Internet Explorer", :category=>:pc, :os=>"Windows 7", :version=>"8.0", :vendor=>"Microsoft"}
31
+ ```
32
+
33
+ Parse user-agent string and returns Hash instance with keys `:name`, `:category`, `:os`, `:version` and `:vendor`.
34
+
35
+ For unknown user-agent (or partially failed to parse), result Hash instance may have value 'UNKNOWN'.
36
+
37
+ * `:category`
38
+ * labels of user terminal type, one of 'pc', 'smartphone', 'mobilephone', 'appliance', 'crawler' or 'misc' (or 'UNKNOWN')
39
+ * `:name`
40
+ * the name of browser, like 'Internet Explorer', 'Firefox', 'GoogleBot'
41
+ * `:version`
42
+ * version string, like '8.0' for IE, '9.0.1' for Firefix, '0.2.149.27' for Chrome, and so on
43
+ * `:os`
44
+ * ex: 'Windows 7', 'Mac OSX', 'iPhone', 'iPad', 'Android'
45
+ * This field used to indicate cellar phone carrier for category 'mobilephone'
46
+ * `:vendor`
47
+ * optional field, shows browser vendor
48
+
49
+ ### Finding crawlers (almost all, not all) in fast
50
+
51
+ ```ruby
52
+ require 'woothee'
53
+ Woothee.is_crawler("Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0)")
54
+ # => false
55
+ ```
56
+
57
+ Try to see useragent's category is 'crawler' or not, by casual(fast) method. Minor case of crawlers is not tested in this method. To check crawler strictly, use `Woothee.parse(str)[:category] == 'crawler'`.
58
+
59
+ * * * * *
60
+
61
+ ## Authors
62
+
63
+ * TAGOMORI Satoshi <tagomoris@gmail.com>
64
+
65
+ ## License
66
+
67
+ Copyright 2012- TAGOMORI Satoshi (tagomoris)
68
+
69
+ Licensed under the Apache License, Version 2.0 (the "License");
70
+ you may not use this file except in compliance with the License.
71
+ You may obtain a copy of the License at
72
+
73
+ http://www.apache.org/licenses/LICENSE-2.0
74
+
75
+ Unless required by applicable law or agreed to in writing, software
76
+ distributed under the License is distributed on an "AS IS" BASIS,
77
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
78
+ See the License for the specific language governing permissions and
79
+ limitations under the License.
data/Rakefile CHANGED
@@ -3,11 +3,11 @@ Bundler::GemHelper.install_tasks
3
3
 
4
4
  require 'rake'
5
5
  $:.unshift File.join(File.dirname(__FILE__), "lib")
6
-
6
+
7
7
  require 'rspec/core'
8
8
  require 'rspec/core/rake_task'
9
-
9
+
10
10
  task :default => :spec
11
-
11
+
12
12
  desc "Run all specs in spec directory"
13
13
  RSpec::Core::RakeTask.new(:spec)
@@ -11,6 +11,7 @@ module Woothee::Appliance
11
11
  when ua.index('PSP (PlayStation Portable);') then Woothee::DataSet.get('PSP')
12
12
  when ua.index('PlayStation Vita') then Woothee::DataSet.get('PSVita')
13
13
  when ua.index('PLAYSTATION 3 ') || ua.index('PLAYSTATION 3;') then Woothee::DataSet.get('PS3')
14
+ when ua.index('PlayStation 4 ') then Woothee::DataSet.get('PS4')
14
15
  else nil
15
16
  end
16
17
  return false unless data
@@ -33,7 +33,7 @@ end
33
33
 
34
34
  module Woothee::DataSet
35
35
  DATASET = {}
36
- # GENERATED from dataset.yaml at Tue Sep 10 14:45:24 JST 2013 by tagomoris
36
+ # GENERATED from dataset.yaml at Tue Dec 3 19:37:52 JST 2013 by tagomoris
37
37
  obj = {:label => 'MSIE', :name => 'Internet Explorer', :type => :browser}
38
38
  obj[:vendor] = 'Microsoft'
39
39
  DATASET[obj[:label]] = obj
@@ -195,6 +195,21 @@ module Woothee::DataSet
195
195
  obj[:category] = :appliance
196
196
  obj[:os] = 'PlayStation 3'
197
197
  DATASET[obj[:label]] = obj
198
+ obj = {:label => 'PS4', :name => 'PlayStation 4', :type => :full}
199
+ obj[:vendor] = 'Sony'
200
+ obj[:category] = :appliance
201
+ obj[:os] = 'PlayStation 4'
202
+ DATASET[obj[:label]] = obj
203
+ obj = {:label => 'Xbox360', :name => 'Xbox 360', :type => :full}
204
+ obj[:vendor] = 'Microsoft'
205
+ obj[:category] = :appliance
206
+ obj[:os] = 'Xbox 360'
207
+ DATASET[obj[:label]] = obj
208
+ obj = {:label => 'XboxOne', :name => 'Xbox One', :type => :full}
209
+ obj[:vendor] = 'Microsoft'
210
+ obj[:category] = :appliance
211
+ obj[:os] = 'Xbox One'
212
+ DATASET[obj[:label]] = obj
198
213
  obj = {:label => 'DigitalTV', :name => 'InternetTVBrowser', :type => :full}
199
214
  obj[:category] = :appliance
200
215
  obj[:os] = 'DigitalTV'
data/lib/woothee/os.rb CHANGED
@@ -9,6 +9,18 @@ module Woothee::OS
9
9
  def self.challenge_windows(ua, result)
10
10
  return false if ua.index("Windows").nil?
11
11
 
12
+ # Xbox Series
13
+ if ua.index("Xbox")
14
+ data = if ua.index("Xbox; Xbox One)")
15
+ Woothee::DataSet.get("XboxOne")
16
+ else
17
+ Woothee::DataSet.get("Xbox360")
18
+ end
19
+ # update browser as appliance
20
+ update_map(result, data)
21
+ return true
22
+ end
23
+
12
24
  data = Woothee::DataSet.get('Win')
13
25
  unless ua =~ /Windows ([ .a-zA-Z0-9]+)[;\\)]/o
14
26
  # Windows, but version unknown
@@ -0,0 +1,95 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- coding: utf-8 -*-
3
+
4
+ require 'yaml'
5
+
6
+ dataset_file = File.dirname(__FILE__) + '/../woothee/dataset.yaml';
7
+ rb_file = File.dirname(__FILE__) + '/../lib/woothee/dataset.rb';
8
+
9
+ generated_timestamp = open("|env LANG=C date") {|io|
10
+ io.readline().chomp
11
+ }
12
+ generated_username = open("|env LANG=C whoami") {|io|
13
+ io.readline().chomp
14
+ }
15
+ timestamp = "# GENERATED from dataset.yaml at #{generated_timestamp} by #{generated_username}"
16
+
17
+ lines = [timestamp]
18
+
19
+ YAML.load_file(dataset_file).each do |dataset|
20
+ label = dataset['label']
21
+ name = dataset['name']
22
+ type = dataset['type']
23
+
24
+ # obj = {:label => 'MSIE', :name => 'Internet Explorer', :type => :browser}
25
+ # obj[:vendor] = 'Microsoft'
26
+ # DATASET['MSIE'] = obj
27
+
28
+ lines.push "obj = {:label => '#{label}', :name => '#{name}', :type => :#{type}}"
29
+ case type
30
+ when 'browser'
31
+ lines.push "obj[:vendor] = '#{dataset['vendor']}'"
32
+ when 'os'
33
+ lines.push "obj[:category] = :#{dataset['category']}"
34
+ when 'full'
35
+ lines.push "obj[:vendor] = '#{dataset['vendor']}'" if dataset['vendor']
36
+ lines.push "obj[:category] = :#{dataset['category']}"
37
+ if dataset['os']
38
+ lines.push "obj[:os] = '#{dataset['os']}'"
39
+ end
40
+ else
41
+ raise StandardError, "unknown type #{type}"
42
+ end
43
+ lines.push "DATASET[obj[:label]] = obj"
44
+ end
45
+
46
+ dynamic_lines = lines.join("\n ") + "\n"
47
+
48
+ module_text = <<EOT
49
+ # -*- coding: utf-8 -*-
50
+ module Woothee
51
+ KEY_LABEL = :label
52
+ KEY_NAME = :name
53
+ KEY_TYPE = :type
54
+ KEY_CATEGORY = :category
55
+ KEY_OS = :os
56
+ KEY_VENDOR = :vendor
57
+ KEY_VERSION = :version
58
+
59
+ TYPE_BROWSER = :browser
60
+ TYPE_OS = :os
61
+ TYPE_FULL = :full
62
+
63
+ CATEGORY_PC = :pc
64
+ CATEGORY_SMARTPHONE = :smartphone
65
+ CATEGORY_MOBILEPHONE = :mobilephone
66
+ CATEGORY_CRAWLER = :crawler
67
+ CATEGORY_APPLIANCE = :appliance
68
+ CATEGORY_MISC = :misc
69
+
70
+ ATTRIBUTE_NAME = :name
71
+ ATTRIBUTE_CATEGORY = :category
72
+ ATTRIBUTE_OS = :os
73
+ ATTRIBUTE_VENDOR = :vendor
74
+ ATTRIBUTE_VERSION = :version
75
+
76
+ VALUE_UNKNOWN = "UNKNOWN"
77
+
78
+ CATEGORY_LIST = [CATEGORY_PC,CATEGORY_SMARTPHONE,CATEGORY_MOBILEPHONE,CATEGORY_CRAWLER,CATEGORY_APPLIANCE,CATEGORY_MISC,VALUE_UNKNOWN]
79
+ ATTRIBUTE_LIST = [ATTRIBUTE_NAME,ATTRIBUTE_CATEGORY,ATTRIBUTE_OS,ATTRIBUTE_VENDOR,ATTRIBUTE_VERSION]
80
+ end
81
+
82
+ module Woothee::DataSet
83
+ DATASET = {}
84
+ #{dynamic_lines}
85
+ DATASET.freeze
86
+
87
+ def self.get(label)
88
+ DATASET[label]
89
+ end
90
+ end
91
+ EOT
92
+
93
+ open(rb_file, 'w') {|io|
94
+ io.write module_text
95
+ }
@@ -5,7 +5,7 @@ $LOAD_PATH.push '../lib' unless $LOAD_PATH.include?('../lib')
5
5
  require 'yaml'
6
6
  require 'woothee'
7
7
 
8
- TESTSET_DIR = File.dirname(__FILE__) + "/../../testsets/";
8
+ TESTSET_DIR = File.dirname(__FILE__) + "/../woothee/testsets/";
9
9
 
10
10
  TARGETS = [
11
11
  ['crawler.yaml','Crawler'],['crawler_google.yaml','Crawler/Google'],
data/woothee.gemspec CHANGED
@@ -1,12 +1,11 @@
1
1
  # encoding: utf-8
2
- # $:.push File.expand_path('../lib', __FILE__)
3
2
 
4
3
  Gem::Specification.new do |gem|
5
4
  gem.name = "woothee"
6
5
  gem.description = "Cross-language UserAgent classifier library, ruby implementation"
7
- gem.homepage = "https://github.com/tagomoris/woothee"
6
+ gem.homepage = "https://github.com/woothee/woothee-ruby"
8
7
  gem.summary = gem.description
9
- gem.version = "0.3.4"
8
+ gem.version = "0.3.5"
10
9
  gem.authors = ["TAGOMORI Satoshi"]
11
10
  gem.email = "tagomoris@gmail.com"
12
11
  gem.has_rdoc = false
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: woothee
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.4
4
+ version: 0.3.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - TAGOMORI Satoshi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-09-10 00:00:00.000000000 Z
11
+ date: 2013-12-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -30,8 +30,13 @@ executables: []
30
30
  extensions: []
31
31
  extra_rdoc_files: []
32
32
  files:
33
+ - .gitignore
34
+ - .gitmodules
35
+ - .travis.yml
33
36
  - Gemfile
37
+ - LICENSE.txt
34
38
  - Makefile
39
+ - README.md
35
40
  - Rakefile
36
41
  - lib/woothee.rb
37
42
  - lib/woothee/appliance.rb
@@ -42,11 +47,12 @@ files:
42
47
  - lib/woothee/mobilephone.rb
43
48
  - lib/woothee/os.rb
44
49
  - lib/woothee/util.rb
50
+ - scripts/dataset_yaml2rb.rb
45
51
  - spec/00_valid_spec.rb
46
52
  - spec/01_dataset_spec.rb
47
53
  - spec/02_run_testsets_spec.rb
48
54
  - woothee.gemspec
49
- homepage: https://github.com/tagomoris/woothee
55
+ homepage: https://github.com/woothee/woothee-ruby
50
56
  licenses: []
51
57
  metadata: {}
52
58
  post_install_message: