Class: Agent212::UserAgent

Inherits:
Object
  • Object
show all
Defined in:
lib/agent212/user_agent.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeUserAgent

Returns a new instance of UserAgent.



9
10
11
# File 'lib/agent212/user_agent.rb', line 9

def initialize
  @parts = [] # either products or strings (comments)
end

Instance Attribute Details

#partsObject (readonly)

Returns the value of attribute parts.



7
8
9
# File 'lib/agent212/user_agent.rb', line 7

def parts
  @parts
end

Class Method Details

.emptyObject



21
22
23
# File 'lib/agent212/user_agent.rb', line 21

def self.empty
  new
end

.parse(user_agent_string) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/agent212/user_agent.rb', line 13

def self.parse(user_agent_string)
  new.tap do |ua|
    unless user_agent_string.nil?
      Parser.parse(user_agent_string).each { |part| ua.parts << part }
    end
  end
end

Instance Method Details

#commentsObject



29
30
31
# File 'lib/agent212/user_agent.rb', line 29

def comments
  @parts.select { |part| part.is_a? String }
end

#empty?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/agent212/user_agent.rb', line 33

def empty?
  @parts.empty?
end

#productsObject



25
26
27
# File 'lib/agent212/user_agent.rb', line 25

def products
  @parts.select { |part| part.is_a? Product }
end

#to_sObject



37
38
39
# File 'lib/agent212/user_agent.rb', line 37

def to_s
  "UserAgent: " + @parts.join(" ")
end