Class: WebMole::UserAgentSwitcher
- Inherits:
-
Object
- Object
- WebMole::UserAgentSwitcher
- Defined in:
- lib/webmole/user_agent_switcher.rb
Constant Summary collapse
- CONFIG_DIR =
File.join(Dir.home, '.config', 'webmole')
- CONFIG_FILE =
File.join(CONFIG_DIR, 'user_agents.yml')
Instance Method Summary collapse
-
#initialize ⇒ UserAgentSwitcher
constructor
A new instance of UserAgentSwitcher.
- #random_user_agent ⇒ Object
Constructor Details
#initialize ⇒ UserAgentSwitcher
Returns a new instance of UserAgentSwitcher.
9 10 11 12 13 14 15 |
# File 'lib/webmole/user_agent_switcher.rb', line 9 def initialize ensure_config_file_exists @user_agents = YAML.load_file(CONFIG_FILE) rescue StandardError => e puts "Warning: Error loading user_agents.yml: #{e.}. Using default user agent.".colorize(:yellow) @user_agents = ['Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36'] end |
Instance Method Details
#random_user_agent ⇒ Object
17 18 19 |
# File 'lib/webmole/user_agent_switcher.rb', line 17 def random_user_agent @user_agents.sample end |