Class: UseragentParser::DeviceParser

Inherits:
Object
  • Object
show all
Defined in:
lib/useragent_parser/parsers/device_parser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pattern, device_replacement = nil) ⇒ DeviceParser

Returns a new instance of DeviceParser.



7
8
9
10
11
# File 'lib/useragent_parser/parsers/device_parser.rb', line 7

def initialize(pattern, device_replacement = nil)
  @pattern = pattern
  @user_agent_re = Regexp.compile(pattern)
  @device_replacement = device_replacement
end

Instance Attribute Details

#device_replacementObject

Returns the value of attribute device_replacement.



5
6
7
# File 'lib/useragent_parser/parsers/device_parser.rb', line 5

def device_replacement
  @device_replacement
end

#patternObject

Returns the value of attribute pattern.



5
6
7
# File 'lib/useragent_parser/parsers/device_parser.rb', line 5

def pattern
  @pattern
end

#user_agent_reObject

Returns the value of attribute user_agent_re.



5
6
7
# File 'lib/useragent_parser/parsers/device_parser.rb', line 5

def user_agent_re
  @user_agent_re
end

Instance Method Details

#match_spans(user_agent_string) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/useragent_parser/parsers/device_parser.rb', line 13

def match_spans(user_agent_string)
  match_spans = []
  match = @user_agent_re.match(user_agent_string)
  if match
    # Return the offsets
  end
end

#parse(user_agent_string) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/useragent_parser/parsers/device_parser.rb', line 21

def parse(user_agent_string)
  device = nil
  match = @user_agent_re.match(user_agent_string)
  if match
    if @device_replacement
      if %r'\$1'.match @device_replacement
        device = @device_replacement.gsub(%r'\$1', match[1])
      else
        device = @device_replacement
      end
    else
      device = match[1]
    end
  end
  return device
end