module Agents

Constants

VERSION

Public Class Methods

is_ipad?(user_agent) click to toggle source
# File lib/agents.rb, line 28
def is_ipad?(user_agent)
  !(user_agent =~ /ipad/i).nil?
end
is_iphone?(user_agent) click to toggle source
# File lib/agents.rb, line 24
def is_iphone?(user_agent)
  !(user_agent =~ /iphone|cpu\siphone/i).nil?
end
random_user_agent(*args) click to toggle source
# File lib/agents.rb, line 7
def random_user_agent(*args)
  args    =   (args.nil? || args.empty?) ? [:desktop] : args
  
  case args.first
    when :phone, :mobile
      (::Agents::Constants::USER_AGENTS[:phones][:iphone] | ::Agents::Constants::USER_AGENTS[:phones][:android])&.sample
    when :tablet
      (::Agents::Constants::USER_AGENTS[:tablets][:ipad] | ::Agents::Constants::USER_AGENTS[:tablets][:android])&.sample
    else
      ::Agents::Constants::USER_AGENTS.dig(*args&.collect(&:to_sym))&.sample
  end
end
runs_ios?(user_agent) click to toggle source
# File lib/agents.rb, line 20
def runs_ios?(user_agent)
  is_iphone?(user_agent) || is_ipad?(user_agent)
end