Module: Termapinator
- Defined in:
- lib/termapinator.rb,
lib/termapinator/version.rb
Constant Summary collapse
- DEFAULT_OPTIONS =
{ size: '640x640', sensor: true, style: 'element:labels|visibility:off' }
- VERSION =
"0.0.2"
Class Method Summary collapse
- .colored_square(color) ⇒ Object
- .google_maps_request(options) ⇒ Object
- .image_to_ascii(image) ⇒ Object
- .load_image(url) ⇒ Object
- .run(options) ⇒ Object
Class Method Details
.colored_square(color) ⇒ Object
46 47 48 |
# File 'lib/termapinator.rb', line 46 def self.colored_square(color) '▇'.color(ChunkyPNG::Color.r(color), ChunkyPNG::Color.g(color), ChunkyPNG::Color.b(color)) end |
.google_maps_request(options) ⇒ Object
22 23 24 25 26 27 |
# File 'lib/termapinator.rb', line 22 def self.google_maps_request() uri = URI.parse("http://maps.googleapis.com/maps/api/staticmap") params = DEFAULT_OPTIONS.merge() uri.query = params.map { |k, v| "#{k}=#{URI.escape(v.to_s)}" }.join('&') uri end |
.image_to_ascii(image) ⇒ Object
40 41 42 43 44 |
# File 'lib/termapinator.rb', line 40 def self.image_to_ascii(image) image.resample_nearest_neighbor!(80, 30) squares = image.pixels.map { |pixel| colored_square(pixel) } squares.each_slice(80).map { |square| square.join }.join("\n") end |
.load_image(url) ⇒ Object
30 31 32 33 34 35 36 37 38 |
# File 'lib/termapinator.rb', line 30 def self.load_image(url) image = nil open(url) do |f| image = ChunkyPNG::Image.from_blob(f.read) end image end |
.run(options) ⇒ Object
16 17 18 19 20 |
# File 'lib/termapinator.rb', line 16 def self.run() image = load_image(google_maps_request()) ascii = image_to_ascii(image) puts ascii end |