Class: UserAgentGenerator::Logic
- Inherits:
-
Object
- Object
- UserAgentGenerator::Logic
- Defined in:
- lib/User_Agent_Generator/logic.rb
Overview
:nodoc:
Instance Method Summary collapse
- #android ⇒ Object
- #browser ⇒ Object
- #chrome(version) ⇒ Object
- #firefox(version) ⇒ Object
-
#initialize(options) ⇒ Logic
constructor
A new instance of Logic.
- #iOS ⇒ Object
- #run ⇒ Object
- #safari(version) ⇒ Object
- #windows ⇒ Object
Constructor Details
#initialize(options) ⇒ Logic
Returns a new instance of Logic.
4 5 6 |
# File 'lib/User_Agent_Generator/logic.rb', line 4 def initialize() = end |
Instance Method Details
#android ⇒ Object
25 26 27 28 |
# File 'lib/User_Agent_Generator/logic.rb', line 25 def android string = 'Android / ' string + browser end |
#browser ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/User_Agent_Generator/logic.rb', line 35 def browser if [:chrome] chrome([:version]) elsif [:firefox] firefox([:version]) elsif [:safari] safari([:version]) else '' end end |
#chrome(version) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/User_Agent_Generator/logic.rb', line 47 def chrome(version) string = "Chrome #{version[0, 2]}: Mozilla/5.0 () AppleWebKit/537.36 (KHTML, like Gecko) Chrome/#{version} Safari/537.36" os_index = string.index('()') + 1 string = [:windows] ? string.insert(os_index, 'Windows NT 6.1; WOW64') : string string = [:android] ? string.insert(os_index, 'Linux; 4.4.2; Nexus 4 Build/KOT49H') : string if [:iOS] string.insert(os_index, 'iPad; CPU OS 7_0_4 like Mac OS X') mobile_index = (string.index('Safari') - 1) string.insert(mobile_index, ' Mobile') else string end end |
#firefox(version) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/User_Agent_Generator/logic.rb', line 61 def firefox(version) fail ArgumentError.new('Firefox not compatible with iOS devices') if [:iOS] string = "Firefox #{version[0, 2]}: Mozilla/5.0 () Gecko/ Firefox/#{version}" os_index = string.index('()') + 1 if [:windows] string = string.insert(os_index, "Windows NT 6.1; WOW64; rv:#{version[0, 2]}.0") gecko_index = string.index('Gecko/') + 6 string.insert(gecko_index, '20100101') elsif [:android] string = string.insert(os_index, "Android; Mobile; rv:#{version[0, 2]}.0") gecko_index = string.index('Gecko/') + 6 string.insert(gecko_index, "#{version}") else string end end |
#iOS ⇒ Object
30 31 32 33 |
# File 'lib/User_Agent_Generator/logic.rb', line 30 def iOS string = 'iOS / ' string + browser end |
#run ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/User_Agent_Generator/logic.rb', line 8 def run if [:windows] windows elsif [:android] android elsif [:iOS] iOS else '' end end |
#safari(version) ⇒ Object
78 79 80 81 82 83 84 |
# File 'lib/User_Agent_Generator/logic.rb', line 78 def safari(version) fail ArgumentError.new('Safari not compatible with Windows') \ if [:windows] fail ArgumentError.new('Safari not compatible with Android devices') \ if [:android] "Safari #{version[0]} (iPad; CPU OS 7_0_4 like Mac OS X) AppleWebKit/537.51.1 (KHTML, like Gecko) Version/#{version} Mobile/11B554a Safari/9537.53" end |
#windows ⇒ Object
20 21 22 23 |
# File 'lib/User_Agent_Generator/logic.rb', line 20 def windows string = 'Windows / ' string + browser end |