Sha256: 78b0af82f5e5b246b0b57dd365452d9127239261cc12ccee4b51edfaca27709c

Contents?: true

Size: 1.06 KB

Versions: 18

Compression:

Stored size: 1.06 KB

Contents

# frozen_string_literal: true

module UserAgentParser
  class Cli
    def initialize(user_agent, options = {})
      @user_agent = user_agent
      @options = options
    end

    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

    private

    def major
      with_version(&:major)
    end

    def minor
      with_version(&:minor)
    end

    def version
      @version ||= @user_agent.version
    end

    def with_version
      yield(version) if version
    end
  end
end

Version data entries

18 entries across 18 versions & 2 rubygems

Version Path
user_agent_parser-2.18.0 lib/user_agent_parser/cli.rb
user_agent_parser-2.17.0 lib/user_agent_parser/cli.rb
user_agent_parser-2.16.0 lib/user_agent_parser/cli.rb
user_agent_parser-2.15.0 lib/user_agent_parser/cli.rb
user_agent_parser-2.14.0 lib/user_agent_parser/cli.rb
user_agent_parser-2.13.0 lib/user_agent_parser/cli.rb
user_agent_parser-2.12.0 lib/user_agent_parser/cli.rb
user_agent_parser-2.11.0 lib/user_agent_parser/cli.rb
user_agent_parser-2.10.0 lib/user_agent_parser/cli.rb
user_agent_parser-2.9.0 lib/user_agent_parser/cli.rb
user_agent_parser-2.8.0 lib/user_agent_parser/cli.rb
user_agent_parser-2.7.0 lib/user_agent_parser/cli.rb
user_agent_parser_livelink-2.6.0 lib/user_agent_parser/cli.rb
user_agent_parser-2.6.0 lib/user_agent_parser/cli.rb
user_agent_parser-2.5.3 lib/user_agent_parser/cli.rb
user_agent_parser-2.5.2 lib/user_agent_parser/cli.rb
user_agent_parser-2.5.1 lib/user_agent_parser/cli.rb
user_agent_parser-2.5.0 lib/user_agent_parser/cli.rb