Class: UserAgentParser::Parser

Inherits:
Object
  • Object
show all
Extended by:
Gem::Deprecate
Defined in:
lib/user_agent_parser/parser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(patterns_path: nil, patterns_paths: []) ⇒ Parser

Returns a new instance of Parser.



29
30
31
32
33
34
# File 'lib/user_agent_parser/parser.rb', line 29

def initialize(patterns_path: nil, patterns_paths: [])
  @patterns_paths = [patterns_path, *patterns_paths].compact
  @patterns_paths = [UserAgentParser::DefaultPatternsPath] if @patterns_paths.empty?

  @ua_patterns, @os_patterns, @device_patterns = load_patterns(@patterns_paths)
end

Instance Attribute Details

#patterns_pathsObject (readonly)

Returns the value of attribute patterns_paths.



27
28
29
# File 'lib/user_agent_parser/parser.rb', line 27

def patterns_paths
  @patterns_paths
end

Instance Method Details

#parse(user_agent) ⇒ Object



36
37
38
39
40
# File 'lib/user_agent_parser/parser.rb', line 36

def parse(user_agent)
  os = parse_os(user_agent)
  device = parse_device(user_agent)
  parse_ua(user_agent, os, device)
end

#patterns_pathObject



42
43
44
# File 'lib/user_agent_parser/parser.rb', line 42

def patterns_path
  patterns_paths.first
end