class UserAgent::Browsers::Base

Public Instance Methods

<=>(other) click to toggle source
# File lib/user_agent/browsers/base.rb, line 6
def <=>(other)
  if respond_to?(:browser) && other.respond_to?(:browser) &&
      browser == other.browser
    version <=> Version.new(other.version)
  else
    false
  end
end
application() click to toggle source
# File lib/user_agent/browsers/base.rb, line 27
def application
  first
end
bot?() click to toggle source
# File lib/user_agent/browsers/base.rb, line 67
def bot?
  # If UA has no application type, its probably generated by a
  # shitty bot.
  if application.nil?
    true
  # Match common case when bots refer to themselves as bots in
  # the application comment. There are no standards for how bots
  # should call themselves so its not an exhaustive method.
  #
  # If you want to expand the scope, override the method and
  # provide your own regexp. Any patches to future extend this
  # list will be rejected.
  elsif detect_comment_match(/bot/i)
    true
  elsif product = application.product
    product.include?('bot')
  else
    false
  end
end
browser() click to toggle source
# File lib/user_agent/browsers/base.rb, line 31
def browser
  application && application.product
end
eql?(other) click to toggle source
# File lib/user_agent/browsers/base.rb, line 15
def eql?(other)
  self == other
end
method_missing(method, *args, &block) click to toggle source
Calls superclass method
# File lib/user_agent/browsers/base.rb, line 51
def method_missing(method, *args, &block)
  detect_product(method) || super
end
mobile?() click to toggle source
# File lib/user_agent/browsers/base.rb, line 55
def mobile?
  if detect_product('Mobile') || detect_comment('Mobile')
    true
  elsif os =~ /Android/
    true
  elsif application && application.detect_comment { |c| c =~ /^IEMobile/ }
    true
  else
    false
  end
end
os() click to toggle source
# File lib/user_agent/browsers/base.rb, line 43
def os
  nil
end
platform() click to toggle source
# File lib/user_agent/browsers/base.rb, line 39
def platform
  nil
end
respond_to?(symbol, include_all = false) click to toggle source
Calls superclass method
# File lib/user_agent/browsers/base.rb, line 47
def respond_to?(symbol, include_all = false)
  detect_product(symbol) ? true : super
end
to_h() click to toggle source
# File lib/user_agent/browsers/base.rb, line 88
def to_h
  return unless application

  hash = {
    :browser => browser,
    :platform => platform,
    :os => os,
    :mobile => mobile?,
    :bot => bot?,
  }

  if version
    hash[:version] = version.to_a
  else
    hash[:version] = nil
  end

  if comment = application.comment
    hash[:comment] = comment.dup
  else
    hash[:comment] = nil
  end

  hash
end
to_s() click to toggle source
# File lib/user_agent/browsers/base.rb, line 19
def to_s
  to_str
end
to_str() click to toggle source
# File lib/user_agent/browsers/base.rb, line 23
def to_str
  join(" ")
end
version() click to toggle source
# File lib/user_agent/browsers/base.rb, line 35
def version
  application && application.version
end

Private Instance Methods

detect_comment(comment) click to toggle source
# File lib/user_agent/browsers/base.rb, line 119
def detect_comment(comment)
  detect { |useragent| useragent.detect_comment { |c| c == comment } }
end
detect_comment_match(regexp) click to toggle source
# File lib/user_agent/browsers/base.rb, line 123
def detect_comment_match(regexp)
  comment_match = nil
  detect { |useragent| useragent.detect_comment { |c| comment_match = c.match(regexp) } }
  comment_match
end
detect_product(product) click to toggle source
# File lib/user_agent/browsers/base.rb, line 115
def detect_product(product)
  detect { |useragent| useragent.product.to_s.downcase == product.to_s.downcase }
end