module Stella class InvalidArgument < RuntimeError attr_accessor :name def initialize(name) @name = name end def message Stella::TEXT.err(:error_invalid_argument, @name) end end class UnavailableAdapter < RuntimeError attr_accessor :name def initialize(name) @name = name end def message Stella::TEXT.err(:error_unavailable_adapter, @name) end end class UnknownValue < RuntimeError attr_accessor :value def initialize(value) @value = value.to_s end def message Stella::TEXT.err(:error_unknown_value, @value) end end class UnsupportedLanguage < RuntimeError end class Util # process_useragents # # We read the useragents.txt file into a hash index which # useful for refering to specific useragents on the command-line # and other places. # # Examples: # --agent=ie-5 # --agent=ff-2.0.0.2-linux # --agent=chrome-windows # --agent=safari-3.0-osx # def self.process_useragents(ua_strs=[]) agents_index = {} return agents_index if ua_strs.empty? ua_strs.each do |ua_str| ua_str.chomp! # remove trailing line separator ua = UserAgent.parse(ua_str) # Standardize the index values # i.e. firefox-3-windows name = ua.browser.downcase.tr(' ', '') version = ua.version.to_i os = ua.platform.downcase.tr(' ', '') # Non-windows operating systems have the OS string inside of "os" # rather than "platform". We look there for the value and then # standardize the values. # i.e. firefox-3-osx if os != 'windows' os = ua.os.downcase os = 'linux' if os.match(/^linux/) os = 'osx' if os.match(/mac os x/) os = 'bsd' if os.match(/bsd/) end # Make sure all arrays exist before we populate them agents_index[name] ||= [] agents_index["#{name}-#{version}"] ||= [] agents_index["#{name}-#{version}-#{os}"] ||= [] agents_index["#{name}-#{os}"] ||= [] # We use this one for failover # Populate each list. agents_index[name] << ua agents_index["#{name}-#{version}"] << ua agents_index["#{name}-#{version}-#{os}"] << ua agents_index["#{name}-#{os}"] << ua end agents_index end # expand_str # # Turns a string like ff-4-freebsd into ["ff","4","freebsd"] # We use this for command-line values liek agent and rampup def self.expand_str(str) str.split(/\s*[,\-]\s*/) # remove extra spaces at the same time. end end end