Sha256: 490d9a25c414a5f6b35212b1a60f2b8ee2a3a5e45f3c7123276aef2858f30964

Contents?: true

Size: 820 Bytes

Versions: 1

Compression:

Stored size: 820 Bytes

Contents

class UserAgent
  attr_reader :app_version
  attr_reader :device_model
  attr_reader :device_os_version
  attr_reader :device_platform
  attr_reader :string

  def initialize(user_agent_string)
    @string = user_agent_string
    parse_string
  end

  def valid?
    @parsed_successfully &&
      !@app_version.to_s.empty? &&
      !@device_model.to_s.empty? &&
      !@device_os_version.to_s.empty? &&
      !@device_platform.to_s.empty?
  end

  private

  def parse_string
    if match = @string.match(/\/([^ ]+) \(([^)]+)\)/)
      @app_version, rest = match.captures
      rest = rest.split(';')
      @device_platform = rest[0].strip
      @device_os_version = rest[1].strip
      @device_model = rest[2].strip
      @parsed_successfully = true
    end
  rescue Exception
    @parsed_successfully = false
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
kill_switch-0.2.0 lib/kill_switch/user_agent.rb