Module: Woothee

Defined in:
lib/woothee.rb,
lib/woothee/dataset.rb,
lib/woothee/version.rb

Defined Under Namespace

Modules: Appliance, Browser, Crawler, DataSet, Misc, MobilePhone, OS, Util

Constant Summary collapse

FILLED =
{
  Woothee::ATTRIBUTE_NAME => Woothee::VALUE_UNKNOWN,
  Woothee::ATTRIBUTE_CATEGORY => Woothee::VALUE_UNKNOWN,
  Woothee::ATTRIBUTE_OS => Woothee::VALUE_UNKNOWN,
  Woothee::ATTRIBUTE_OS_VERSION => Woothee::VALUE_UNKNOWN,
  Woothee::ATTRIBUTE_VERSION => Woothee::VALUE_UNKNOWN,
  Woothee::ATTRIBUTE_VENDOR => Woothee::VALUE_UNKNOWN,
}.freeze
KEY_LABEL =
:label
KEY_NAME =
:name
KEY_TYPE =
:type
KEY_CATEGORY =
:category
KEY_OS =
:os
KEY_OS_VERSION =
:os_version
KEY_VENDOR =
:vendor
KEY_VERSION =
:version
TYPE_BROWSER =
:browser
TYPE_OS =
:os
TYPE_FULL =
:full
CATEGORY_PC =
:pc
CATEGORY_SMARTPHONE =
:smartphone
CATEGORY_MOBILEPHONE =
:mobilephone
CATEGORY_CRAWLER =
:crawler
CATEGORY_APPLIANCE =
:appliance
CATEGORY_MISC =
:misc
ATTRIBUTE_NAME =
:name
ATTRIBUTE_CATEGORY =
:category
ATTRIBUTE_OS =
:os
ATTRIBUTE_OS_VERSION =
:os_version
ATTRIBUTE_VENDOR =
:vendor
ATTRIBUTE_VERSION =
:version
VALUE_UNKNOWN =
"UNKNOWN"
CATEGORY_LIST =
[CATEGORY_PC,CATEGORY_SMARTPHONE,CATEGORY_MOBILEPHONE,CATEGORY_CRAWLER,CATEGORY_APPLIANCE,CATEGORY_MISC,VALUE_UNKNOWN]
ATTRIBUTE_LIST =
[ATTRIBUTE_NAME,ATTRIBUTE_CATEGORY,ATTRIBUTE_OS,ATTRIBUTE_VENDOR,ATTRIBUTE_VERSION,ATTRIBUTE_OS_VERSION]
VERSION =
"1.2.0"

Class Method Summary collapse

Class Method Details

.exec_parse(useragent) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/woothee.rb', line 22

def self.exec_parse(useragent)
  result = {}

  return result if useragent.nil? or useragent.length < 1 or useragent == '-'

  if try_crawler(useragent, result)
    return result
  end

  if try_browser(useragent, result)
    if try_os(useragent, result)
      return result
    else
      return result
    end
  end

  if try_mobilephone(useragent, result)
    return result
  end

  if try_appliance(useragent, result)
    return result
  end

  if try_misc(useragent, result)
    return result
  end

  # browser unknown. check os only
  if try_os(useragent, result)
    return result
  end

  if try_rare_cases(useragent, result)
    return result
  end

  result
end

.fill_result(result) ⇒ Object



161
162
163
# File 'lib/woothee.rb', line 161

def self.fill_result(result)
  FILLED.merge(result)
end

.is_crawler(useragent) ⇒ Object



18
19
20
# File 'lib/woothee.rb', line 18

def self.is_crawler(useragent)
  !!useragent && useragent.length > 0 and useragent != '-' and try_crawler(useragent, {})
end

.parse(useragent) ⇒ Object



14
15
16
# File 'lib/woothee.rb', line 14

def self.parse(useragent)
   fill_result(exec_parse(useragent))
end

.try_appliance(useragent, result) ⇒ Object



123
124
125
126
127
128
129
130
131
# File 'lib/woothee.rb', line 123

def self.try_appliance(useragent, result)
  return true if Woothee::Appliance.challenge_playstation(useragent, result)

  return true if Woothee::Appliance.challenge_nintendo(useragent, result)

  return true if Woothee::Appliance.challenge_digitaltv(useragent, result)

  false
end

.try_browser(useragent, result) ⇒ Object



71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/woothee.rb', line 71

def self.try_browser(useragent, result)
  return true if Woothee::Browser.challenge_msie(useragent, result)

  return true if Woothee::Browser.challenge_safari_chrome(useragent, result)

  return true if Woothee::Browser.challenge_firefox(useragent, result)

  return true if Woothee::Browser.challenge_opera(useragent, result)

  return true if Woothee::Browser.challenge_webview(useragent, result)

  false
end

.try_crawler(useragent, result) ⇒ Object



63
64
65
66
67
68
69
# File 'lib/woothee.rb', line 63

def self.try_crawler(useragent, result)
  return true if Woothee::Crawler.challenge_google(useragent, result)

  return true if Woothee::Crawler.challenge_crawlers(useragent, result)

  false
end

.try_misc(useragent, result) ⇒ Object



133
134
135
136
137
# File 'lib/woothee.rb', line 133

def self.try_misc(useragent, result)
  return true if Woothee::Misc.challenge_desktoptools(useragent, result)

  false
end

.try_mobilephone(useragent, result) ⇒ Object



109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/woothee.rb', line 109

def self.try_mobilephone(useragent, result)
  return true if Woothee::MobilePhone.challenge_docomo(useragent, result)

  return true if Woothee::MobilePhone.challenge_au(useragent, result)

  return true if Woothee::MobilePhone.challenge_softbank(useragent, result)

  return true if Woothee::MobilePhone.challenge_willcom(useragent, result)

  return true if Woothee::MobilePhone.challenge_misc(useragent, result)

  false
end

.try_os(useragent, result) ⇒ Object



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/woothee.rb', line 85

def self.try_os(useragent, result)
  return true if Woothee::OS.challenge_windows(useragent, result)

  # OSX PC and iOS devices (strict check)
  return true if Woothee::OS.challenge_osx(useragent, result)

  # Linux PC and Android
  return true if Woothee::OS.challenge_linux(useragent, result)

  # all useragents matches /(iPhone|iPad|iPod|Android|BlackBerry)/
  return true if Woothee::OS.challenge_smartphone(useragent, result)

  # mobile phones like KDDI-.*
  return true if Woothee::OS.challenge_mobilephone(useragent, result)

  # Nintendo DSi/Wii with Opera
  return true if Woothee::OS.challenge_appliance(useragent, result)

  # Win98, BSD, classic MacOS, ...
  return true if Woothee::OS.challenge_misc(useragent, result)

  false
end

.try_rare_cases(useragent, result) ⇒ Object



139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'lib/woothee.rb', line 139

def self.try_rare_cases(useragent, result)
  return true if Woothee::Misc.challenge_smartphone_patterns(useragent, result)

  return true if Woothee::Browser.challenge_sleipnir(useragent, result)

  return true if Woothee::Misc.challenge_http_library(useragent, result)

  return true if Woothee::Misc.challenge_maybe_rss_reader(useragent, result)

  return true if Woothee::Crawler.challenge_maybe_crawler(useragent, result)

  false
end