Sha256: ec315fed53d60644b4e6260b3a132d95be4fbd1847176927900e9a672b44c113
Contents?: true
Size: 1.27 KB
Versions: 1
Compression:
Stored size: 1.27 KB
Contents
module Ramesh class Client MESHES_INDEX_URL = "http://tokyo-ame.jwa.or.jp/scripts/mesh_index.js" def initialize(logger) @logger = logger end def download_image(save_dir, minute = 0) unless valid_minutes?(minute) raise ArgumentError, "minutes must be a number; 0, 5, 10, ... 120" end image_name = name_from_minute(minute) image = Image.new(image_name, background_image, mask_image) image.save(save_dir, image_name) @logger.info("Downloaded: #{image_name}.jpg") end def download_sequential_images(save_dir, from, to) unless valid_minutes?(from) && valid_minutes?(to) raise ArgumentError, "minutes must be a number; 0, 5, 10, ... 120" end (from..to).step(5) do |minute| download_image(save_dir, minute) end end private def background_image @background_image ||= Image.background_image end def mask_image @mask_image ||= Image.mask_image end def meshes_index @meshes_index ||= open(MESHES_INDEX_URL).read.gsub(/[^0-9,]/, "").split(",") end def name_from_minute(minute) meshes_index[minute / 5] end def valid_minutes?(minutes) (minutes >= 0) && (minutes <= 120) && (minutes % 5 == 0) end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
ramesh-1.2.0 | lib/ramesh/client.rb |