Class: UserAgentParser::Cli

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

Instance Method Summary collapse

Constructor Details

#initialize(user_agent, options = {}) ⇒ Cli

Returns a new instance of Cli.


5
6
7
8
# File 'lib/user_agent_parser/cli.rb', line 5

def initialize(user_agent, options = {})
  @user_agent = user_agent
  @options = options
end

Instance Method Details

#run!Object


10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/user_agent_parser/cli.rb', line 10

def run!
  if @options[:family]
    @user_agent.family
  elsif @options[:name]
    @user_agent.name
  elsif @options[:version]
    with_version(&:to_s)
  elsif @options[:major]
    major
  elsif @options[:minor]
    minor
  elsif @options[:os]
    @user_agent.os.to_s
  elsif (format = @options[:format])
    format
      .gsub('%f', @user_agent.family)
      .gsub('%n', @user_agent.name)
      .gsub('%v', version.to_s)
      .gsub('%M', major.to_s)
      .gsub('%m', minor.to_s)
      .gsub('%o', @user_agent.os.to_s)
  else
    @user_agent.to_s
  end
end