Class: UserAgent

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type) ⇒ UserAgent

Returns a new instance of UserAgent.



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/user_agent.rb', line 7

def initialize(type)
  @type = type
  ua_types = ["crawler", "desktop_browser", "mobile_browser", "console",
    "offline_browser", "email_client", "link_checker", "email_collector",
    "validator", "feed_reader", "library", "cloud_platform", "other"]
  ua_h = YAML.load_file(File.expand_path("../data/user_agents.yml", __FILE__))
  if ua_types.include?(type)
    @string = ua_h[type].sample.to_s
  else
    @string = ua_h.values.flatten.sample
  end
end

Instance Attribute Details

#stringObject

Returns the value of attribute string.



5
6
7
# File 'lib/user_agent.rb', line 5

def string
  @string
end

#typeObject

Returns the value of attribute type.



5
6
7
# File 'lib/user_agent.rb', line 5

def type
  @type
end