Class: Everoute

Inherits:
Object
  • Object
show all
Defined in:
lib/everoute.rb

Constant Summary collapse

BASE_URL =
'http://evemaps.dotlan.net/route/'
TRADEHUBS =
%w(Jita Rens Hek Amarr Dodixie)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeEveroute

Returns a new instance of Everoute.



13
14
15
# File 'lib/everoute.rb', line 13

def initialize
  @agent = Mechanize.new
end

Instance Attribute Details

#routeObject

Returns the value of attribute route.



11
12
13
# File 'lib/everoute.rb', line 11

def route
  @route
end

Instance Method Details

#find_tradehubs(start_sys, hisec) ⇒ Object



39
40
41
42
43
44
45
46
47
# 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) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# 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