Class: Gricer::ActiveRecord::Agent

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
Gricer::ActiveModel::Statistics, LimitStrings
Defined in:
app/models/gricer/active_record/agent.rb

Overview

ActiveRecord Model for User Agent Statistics

Constant Summary collapse

AGENT_CLASSES =

The agent class constant defines numeric values for the different agent types to be stored in a database.

{
  0x1000 => :browser,
  0x2000 => :mobile_browser,
  0x0001 => :bot
}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from LimitStrings

included

Methods included from Gricer::ActiveModel::Statistics

included, #model_type

Instance Attribute Details

#agent_classString

The current value of the classification of the user agent.

See AGENT_CLASSES for possible values.

Returns:

  • (String)

    the current value of agent_class



33
34
35
# File 'app/models/gricer/active_record/agent.rb', line 33

def agent_class
  @agent_class
end

#engine_nameString

The current value of the name of the engine used by the user agent

Returns:

  • (String)

    the current value of engine_name



33
34
35
# File 'app/models/gricer/active_record/agent.rb', line 33

def engine_name
  @engine_name
end

#engine_versionString

The current value of the version of the engine used by the user agent

Returns:

  • (String)

    the current value of engine_version



33
34
35
# File 'app/models/gricer/active_record/agent.rb', line 33

def engine_version
  @engine_version
end

#full_versionString

The current value of user agent’s full version. This means it does include all sub version numbers.

Returns:

  • (String)

    the current value of full_version



33
34
35
# File 'app/models/gricer/active_record/agent.rb', line 33

def full_version
  @full_version
end

#major_versionString

The current value of user agent’s major version. This means it does include only the first number after a dot.

Returns:

  • (String)

    the current value of major_version



33
34
35
# File 'app/models/gricer/active_record/agent.rb', line 33

def major_version
  @major_version
end

#nameString

The current value of user agent’s name. (e.g. ‘Firefox’, ‘Chrome’, ‘Internet Explorer’)

Returns:

  • (String)

    the current value of name



33
34
35
# File 'app/models/gricer/active_record/agent.rb', line 33

def name
  @name
end

#osString

The current value of the OS the user agent is hosted on.

Returns:

  • (String)

    the current value of os



33
34
35
# File 'app/models/gricer/active_record/agent.rb', line 33

def os
  @os
end

#request_headerString

The current value of user agent string as within the HTTP request.

Returns:

  • (String)

    the current value of request_header



33
34
35
# File 'app/models/gricer/active_record/agent.rb', line 33

def request_header
  @request_header
end

Class Method Details

.browsersActiveRecord::Relation

Filter out anything that is not a Browser or MobileBrowser

Returns:

  • (ActiveRecord::Relation)


52
53
54
# File 'app/models/gricer/active_record/agent.rb', line 52

def self.browsers
  self.where("\"#{self.table_name}\".\"agent_class_id\" IN (?)", [0x1000, 0x2000])
end

Instance Method Details

#calculate_agent_infoObject



71
72
73
74
# File 'app/models/gricer/active_record/agent.rb', line 71

def calculate_agent_info    
  return if request_header.blank?
  self.attributes = Gricer::Parsers::Agent.get_info request_header
end