Class: UserAgentRandomizer::UserAgent
- Inherits:
-
Object
- Object
- UserAgentRandomizer::UserAgent
- Defined in:
- lib/user_agent_randomizer/user_agent.rb
Instance Attribute Summary collapse
-
#string ⇒ Object
Returns the value of attribute string.
-
#type ⇒ Object
Returns the value of attribute type.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ UserAgent
constructor
A new instance of UserAgent.
Constructor Details
#initialize(options = {}) ⇒ UserAgent
Returns a new instance of UserAgent.
7 8 9 10 |
# File 'lib/user_agent_randomizer/user_agent.rb', line 7 def initialize( = {}) @type = [:type] @string = [:string] end |
Instance Attribute Details
#string ⇒ Object
Returns the value of attribute string.
5 6 7 |
# File 'lib/user_agent_randomizer/user_agent.rb', line 5 def string @string end |
#type ⇒ Object
Returns the value of attribute type.
5 6 7 |
# File 'lib/user_agent_randomizer/user_agent.rb', line 5 def type @type end |
Class Method Details
.fetch(options = {}) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/user_agent_randomizer/user_agent.rb', line 12 def self.fetch( = {}) type = [:type] ua_types = UserAgentRandomizer.user_agent_types user_agents_hash = UserAgentRandomizer.user_agents_hash if ua_types.include?(type) UserAgentRandomizer::UserAgent.new(type: type, string: user_agents_hash[type].sample) else ua = UserAgentRandomizer.user_agents_array.sample UserAgentRandomizer::UserAgent.new(type: ua[:type], string: ua[:string]) end end |