Class: Sc2::MapFile
- Inherits:
-
Object
- Object
- Sc2::MapFile
- Defined in:
- lib/sc2ai/local_play/map_file.rb
Overview
Helps easily locate a map and fetch input for Api::LocalMap
Constant Summary collapse
- EXTENSION =
File extension used for maps
".SC2Map"
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
-
#data ⇒ String?
Returns contents of map file for user with LocalMap.map_data.
-
#initialize(name) ⇒ MapFile
constructor
Accepts a map file name and initializes a local map object.
Constructor Details
#initialize(name) ⇒ MapFile
Accepts a map file name and initializes a local map object
21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/sc2ai/local_play/map_file.rb', line 21 def initialize(name) raise Error if name.empty? name = "#{name}#{EXTENSION}" unless name.end_with? EXTENSION @path = name.to_s return if Pathname(name).absolute? @path = Pathname(Paths.maps_dir).glob("**/#{name}").first.to_s if Paths.wsl? @path = Paths.wsl_to_win(path: @path) end end |
Instance Attribute Details
#path ⇒ Object
Returns the value of attribute path.
11 12 13 |
# File 'lib/sc2ai/local_play/map_file.rb', line 11 def path @path end |
Instance Method Details
#data ⇒ String?
Returns contents of map file for user with LocalMap.map_data
37 38 39 40 41 42 |
# File 'lib/sc2ai/local_play/map_file.rb', line 37 def data file = Pathname(@path) return file.read if file.exist? nil end |