Class: Tile
- Inherits:
-
Object
- Object
- Tile
- Defined in:
- lib/tiler/tile.rb
Instance Attribute Summary collapse
-
#file ⇒ Object
Returns the value of attribute file.
-
#x ⇒ Object
readonly
Returns the value of attribute x.
-
#y ⇒ Object
readonly
Returns the value of attribute y.
-
#z ⇒ Object
readonly
Returns the value of attribute z.
Instance Method Summary collapse
- #download(dir) ⇒ Object
- #downloaded? ⇒ Boolean
-
#initialize(args) ⇒ Tile
constructor
A new instance of Tile.
- #local_file_name ⇒ Object
- #remote_url ⇒ Object
Constructor Details
#initialize(args) ⇒ Tile
Returns a new instance of Tile.
11 12 13 14 15 16 |
# File 'lib/tiler/tile.rb', line 11 def initialize(args) @x = args[:x] @y = args[:y] @z = args[:z] @source = args[:source] || "sattelite" end |
Instance Attribute Details
#file ⇒ Object
Returns the value of attribute file.
9 10 11 |
# File 'lib/tiler/tile.rb', line 9 def file @file end |
#x ⇒ Object (readonly)
Returns the value of attribute x.
7 8 9 |
# File 'lib/tiler/tile.rb', line 7 def x @x end |
#y ⇒ Object (readonly)
Returns the value of attribute y.
7 8 9 |
# File 'lib/tiler/tile.rb', line 7 def y @y end |
#z ⇒ Object (readonly)
Returns the value of attribute z.
7 8 9 |
# File 'lib/tiler/tile.rb', line 7 def z @z end |
Instance Method Details
#download(dir) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/tiler/tile.rb', line 24 def download(dir) uri = URI.parse(remote_url) Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https') do |http| resp = http.get(uri.path) file = Tempfile.new("x_#{x}_y_#{y}_z_#{z}", dir, 'wb+') file.write(resp.body) file.flush puts "downloaded #{remote_url} to #{file.path}" @file = file @local_file_name = file.path file.close file end end |
#downloaded? ⇒ Boolean
45 46 47 |
# File 'lib/tiler/tile.rb', line 45 def downloaded? !@local_file_name.nil? end |
#local_file_name ⇒ Object
40 41 42 |
# File 'lib/tiler/tile.rb', line 40 def local_file_name @local_file_name end |
#remote_url ⇒ Object
19 20 21 |
# File 'lib/tiler/tile.rb', line 19 def remote_url "https://khms0.google.com/kh/v=143&src=app&x=#{x}&y=#{y}&z=#{z.to_s}" end |