Class: UseragentParser::OSParser

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pattern, os_replacement = nil) ⇒ OSParser

Returns a new instance of OSParser.



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

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

Instance Attribute Details

#family_replacementObject

Returns the value of attribute family_replacement.



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

def family_replacement
  @family_replacement
end

#major_replacementObject

Returns the value of attribute major_replacement.



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

def major_replacement
  @major_replacement
end

#patternObject

Returns the value of attribute pattern.



5
6
7
# File 'lib/useragent_parser/parsers/os_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/os_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/os_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
37
# File 'lib/useragent_parser/parsers/os_parser.rb', line 21

def parse(user_agent_string)
  os, os_v1, os_v2, os_v3, os_v4 = nil, nil, nil, nil, nil
  match = @user_agent_re.match(user_agent_string)
  if match
    if @os_replacement
      os = @os_replacement
    else
      os = match[1]
    end

    os_v1 = match[2] if match.size >= 3
    os_v2 = match[3] if match.size >= 4
    os_v3 = match[4] if match.size >= 5
    os_v4 = match[5] if match.size >= 6
  end
  return os, os_v1, os_v2, os_v3, os_v4
end