Class: PodIdent::Detector

Inherits:
Object
  • Object
show all
Defined in:
lib/pod_ident.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user_agent_string) ⇒ Detector

Returns a new instance of Detector.



17
18
19
# File 'lib/pod_ident.rb', line 17

def initialize(user_agent_string)
  @user_agent_string = user_agent_string
end

Instance Attribute Details

#resultObject

Returns the value of attribute result.



11
12
13
# File 'lib/pod_ident.rb', line 11

def result
  @result
end

#user_agent_stringObject (readonly)

Returns the value of attribute user_agent_string.



10
11
12
# File 'lib/pod_ident.rb', line 10

def user_agent_string
  @user_agent_string
end

Class Method Details

.bot?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/pod_ident.rb', line 33

def self.bot?
  find_rule_bots
end

.detect(user_agent_string) ⇒ Object



13
14
15
# File 'lib/pod_ident.rb', line 13

def self.detect(user_agent_string)
  new(user_agent_string).detect
end

Instance Method Details

#detectObject



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/pod_ident.rb', line 21

def detect
  # !~ /[^[:space:]]/ is what Active Support does to detect blank strings
  return nil if user_agent_string !~ /[^[:space:]]/

  rule = find_rule || find_rule_bots

  self.result = DetectionResult.new(rule, user_agent_string)
  identify_platform if result.positive?

  result
end