Sha256: 617d7f587b66f1cad897fd26d3c3d9e1e3a28b558c62a5014c2d1dd54ab6f609

Contents?: true

Size: 932 Bytes

Versions: 14

Compression:

Stored size: 932 Bytes

Contents

module Ahoy
  module Deckhands
    class TechnologyDeckhand
      def initialize(user_agent)
        @user_agent = user_agent
      end

      def browser
        agent.name
      end

      def os
        agent.os.name
      end

      def device_type
        @device_type ||= begin
          browser = Browser.new(@user_agent)
          if browser.bot?
            "Bot"
          elsif browser.device.tv?
            "TV"
          elsif browser.device.console?
            "Console"
          elsif browser.device.tablet?
            "Tablet"
          elsif browser.device.mobile?
            "Mobile"
          else
            "Desktop"
          end
        end
      end

      protected

      def agent
        @agent ||= self.class.user_agent_parser.parse(@user_agent)
      end

      # performance
      def self.user_agent_parser
        @user_agent_parser ||= UserAgentParser::Parser.new
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
ahoy_matey-1.6.1 lib/ahoy/deckhands/technology_deckhand.rb
ahoy_matey-1.6.0 lib/ahoy/deckhands/technology_deckhand.rb
ahoy_matey-1.5.5 lib/ahoy/deckhands/technology_deckhand.rb
ahoy_matey-1.5.4 lib/ahoy/deckhands/technology_deckhand.rb
ahoy_matey-1.5.3 lib/ahoy/deckhands/technology_deckhand.rb
ahoy_matey-1.5.2 lib/ahoy/deckhands/technology_deckhand.rb
ahoy_matey-1.5.1 lib/ahoy/deckhands/technology_deckhand.rb
ahoy_matey-1.5.0 lib/ahoy/deckhands/technology_deckhand.rb
ahoy_matey-1.4.2 lib/ahoy/deckhands/technology_deckhand.rb
ahoy_matey-1.4.1 lib/ahoy/deckhands/technology_deckhand.rb
ahoy_matey-1.4.0 lib/ahoy/deckhands/technology_deckhand.rb
ahoy_matey-1.3.1 lib/ahoy/deckhands/technology_deckhand.rb
ahoy_matey-1.3.0 lib/ahoy/deckhands/technology_deckhand.rb
ahoy_matey-1.2.2 lib/ahoy/deckhands/technology_deckhand.rb