Sha256: 5dabb765190f1d1ff5bf919aa363b90bae69c2931f000928e6b9560fbc966697

Contents?: true

Size: 941 Bytes

Versions: 15

Compression:

Stored size: 941 Bytes

Contents

# frozen_string_literal: true

module UserAgentParser
  class UserAgent
    DEFAULT_FAMILY = 'Other'

    attr_reader :family, :version, :os, :device

    alias name family

    def initialize(family = nil, version = nil, os = nil, device = nil)
      @family = family || DEFAULT_FAMILY
      @version = version
      @os = os
      @device = device
    end

    def to_s
      string = family
      string += " #{version}" if version
      string
    end

    def inspect
      string = to_s
      string += " (#{os})" if os
      string += " (#{device})" if device
      "#<#{self.class} #{string}>"
    end

    def eql?(other)
      self.class.eql?(other.class) &&
        family == other.family &&
        version == other.version &&
        os == other.os
    end

    alias == eql?

    def to_h
      {
        device: device.to_h,
        family: family,
        os: os.to_h,
        version: version.to_h
      }
    end
  end
end

Version data entries

15 entries across 15 versions & 2 rubygems

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