Class: DodMaps::Installer

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

Constant Summary collapse

STEAM_PATH =
File.join(ENV['HOME'], "Library", "Application Support", "Steam")

Instance Method Summary collapse

Constructor Details

#initialize(username = nil) ⇒ Installer

Returns a new instance of Installer.



7
8
9
10
# File 'lib/dod_maps/installer.rb', line 7

def initialize(username=nil)
  @username = username
  @maps_dir = File.join(STEAM_PATH, "SteamApps", steam_username, "day of defeat source", "dod", "maps")
end

Instance Method Details

#install(pattern) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/dod_maps/installer.rb', line 12

def install(pattern)
  
  make_request("/maps.json?q=#{pattern}") do |maps|
    if maps.any?
      if maps.size > 1
        puts "Which one do you want?"
        options = maps.map { |r| r["file_file_name"] }.push('all', 'none')

        options.each_with_index do |option, i|
          puts "#{i}: #{options[i]}"
        end

        answer = $stdin.gets.chomp

        case options[answer.to_i]
        when 'all'
          download_maps maps
        when 'none'
          exit 0
        else
          download_maps [maps[answer.to_i]]
        end
      else
        download_maps maps
      end
    else
      puts "No maps found."
    end
  end
end

#syncObject



43
44
45
46
47
48
49
50
51
52
53
# File 'lib/dod_maps/installer.rb', line 43

def sync
  # TODO
  # Make a new api call on the server side, just returns all of the maps if no query string is supplied
  make_request("/maps.json") do |maps|
    local_maps = Dir.glob("#{@maps_dir}/*.bsp").map{ |m| File.split(m).last }
    maps.delete_if do |map| 
      local_maps.include? map["file_file_name"]
    end
    download_maps maps, true
  end
end