class Everoute
Constants
- BASE_URL
- TRADEHUBS
Attributes
route[RW]
Public Class Methods
new()
click to toggle source
# File lib/everoute.rb, line 13 def initialize @agent = Mechanize.new end
Public Instance Methods
find_tradehubs(start_sys, hisec)
click to toggle source
# File lib/everoute.rb, line 39 def find_tradehubs(start_sys, hisec) output = "" TRADEHUBS.each do |hub| temp_arr = [start_sys, hub] route = travel(temp_arr, hisec) output << "#{hub}: #{route.size} " end output end
travel(system_arr, hisec=0)
click to toggle source
# File lib/everoute.rb, line 17 def travel(system_arr, hisec=0) sys_string = "" sys_string << "2:" if hisec == "1" sys_string << system_arr[0] system_arr.each_with_index do |sys, i| next if i == 0 sys_string << ":" + sys end puts sys_string page = @agent.get BASE_URL+sys_string arr = page.parser.xpath('//html/body/div/div/div[2]/div[2]/div/div/table/tr') route = [] arr.each_with_index do |a, i| next if i == 0 scan = [i] scan.concat a.to_s.scan(/<tr.*?>\n<td.*?<\/td>\n.*?<td>(.*?)<\/td>\n.*?<a.*?<a.*?>(.*?)<\/a>.*?<span.*?>(.*?)<\/span>.*?<i>(.*?)<\/i>.*?<td.*?>/m)[0] scan[1] = scan[1].scan(/.*?<a.*?<a.*?>(.*?)<\/a>.*?/m)[0][0] if scan[1].scan(/.*?<a.*?<a.*?>(.*?)<\/a>.*?/m)[0] route << Evesystem.new(scan) end route end