ramesh 1.2.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f095feb67813f3fc287cae0facf015f91cb6a8ed
4
- data.tar.gz: 7e375fa8880fa9cf421c74944c6cd8f9c4ec19ff
3
+ metadata.gz: 70c9be78a66d6d02b4a882874ff795aaa5fd13d0
4
+ data.tar.gz: b057347aca5b9b104358c8e810d08e70cbdd08cd
5
5
  SHA512:
6
- metadata.gz: 6842b6ad926081e3f31064693b1505bbd26ae5cfbbb96d7136bb2ad4f0441bd94fe988b67db492638f59cf2db4e673fb134ee7644ca2740fca6f4a1b3bb62fe0
7
- data.tar.gz: bab705ad4c7ff24a27b47f91efd0c86b6558725cd5fd3d829301da45616fb09ddc5fb8222dcba53b79899286f1431bfa3162265e856ce576d2e91cf592136691
6
+ metadata.gz: bfcd3e5df4f56bc52571c983bf2c296dbee2896eb33089a852353aa77161420ee3a57a17b2707323533976e8e86d71a1d204bb221cfc774dae229e9222899851
7
+ data.tar.gz: fde72af13834220b9ad77f62486fed6d8d6a9fbf9733545e37707825dea0bcb6bab8f266f6ab62b81cd7bb4b4bbc0c1abfa5226fcd89f50abe8e58be68a34889
data/bin/ramesh CHANGED
@@ -5,16 +5,18 @@ require "ramesh"
5
5
 
6
6
  USAGE = <<-EOS
7
7
  Usage:
8
- ramesh [-d save_dir] download the latest image
9
- ramesh [-d save_dir] 0-120 download the image specified minutes before
10
- ramesh [-d save_dir] 0-120 0-120 download images within a specified range
11
- ramesh -h, --help show this usage
8
+ ramesh [-d save_dir] [-f filename] download the latest image
9
+ ramesh [-d save_dir] [-f filename] 0..120 download the image specified minutes before
10
+ ramesh [-d save_dir] [-f filename] 0..120 0..120 download images within a specified range
11
+ ramesh -h, --help show this usage
12
12
  EOS
13
13
 
14
14
  save_dir = Dir.pwd
15
+ filename = nil
15
16
 
16
17
  parser = OptionParser.new(USAGE) do |opt|
17
18
  opt.on("-d", "--dir=VAL", "Save directory (default: current directory)") { |val| save_dir = val }
19
+ opt.on("-f", "--filename=VAL", "Save file name (default: timestamp index of downloaded image)") { |val| filename = val }
18
20
  end
19
21
 
20
22
  argv = parser.parse(ARGV)
@@ -23,11 +25,11 @@ client = Ramesh::Client.new(Ramesh::Logger.new(STDOUT))
23
25
 
24
26
  case argv.length
25
27
  when 0
26
- client.download_image(save_dir)
28
+ client.download_image(0, save_dir, filename)
27
29
  when 1
28
- client.download_image(save_dir, argv[0].to_i)
30
+ client.download_image(argv[0].to_i, save_dir, filename)
29
31
  when 2
30
- client.download_sequential_images(save_dir, argv[0].to_i, argv[1].to_i)
32
+ client.download_sequential_images(argv[0].to_i, argv[1].to_i, save_dir)
31
33
  else
32
34
  $stderr.puts USAGE
33
35
  exit 1
@@ -6,19 +6,20 @@ module Ramesh
6
6
  @logger = logger
7
7
  end
8
8
 
9
- def download_image(save_dir, minute = 0)
9
+ def download_image(minute, save_dir, filename = nil)
10
10
  unless valid_minutes?(minute)
11
11
  raise ArgumentError, "minutes must be a number; 0, 5, 10, ... 120"
12
12
  end
13
13
 
14
14
  image_name = name_from_minute(minute)
15
+ filename ||= "#{image_name}.jpg"
15
16
  image = Image.new(image_name, background_image, mask_image)
16
- image.save(save_dir, image_name)
17
+ image.save(save_dir, filename)
17
18
 
18
- @logger.info("Downloaded: #{image_name}.jpg")
19
+ @logger.info("Downloaded: #{filename}")
19
20
  end
20
21
 
21
- def download_sequential_images(save_dir, from, to)
22
+ def download_sequential_images(from, to, save_dir)
22
23
  unless valid_minutes?(from) && valid_minutes?(to)
23
24
  raise ArgumentError, "minutes must be a number; 0, 5, 10, ... 120"
24
25
  end
@@ -26,8 +26,8 @@ module Ramesh
26
26
  @image = composite_images(image_list)
27
27
  end
28
28
 
29
- def save(save_dir, image_name)
30
- save_path = File.join(save_dir, "#{image_name}.jpg")
29
+ def save(save_dir, filename)
30
+ save_path = File.join(save_dir, filename)
31
31
  @image.write(save_path)
32
32
  end
33
33
 
@@ -1,3 +1,3 @@
1
1
  module Ramesh
2
- VERSION = "1.2.0"
2
+ VERSION = "1.3.0"
3
3
  end
@@ -26,57 +26,96 @@ module Ramesh
26
26
  end
27
27
 
28
28
  describe "#download_image" do
29
+ let(:download_image) do
30
+ client.download_image(minute, tmpdir, filename)
31
+ end
32
+
33
+ let(:minute) do
34
+ 0
35
+ end
36
+
37
+ let(:filename) do
38
+ nil
39
+ end
40
+
29
41
  before do
30
42
  image = double(write: true)
31
43
  allow(Image).to receive(:download_image).and_return(image)
32
44
  allow_any_instance_of(Image).to receive(:composite_images).and_return(image)
33
45
  end
34
46
 
35
- context "when minute is not specified" do
36
- it "should download the current image" do
37
- expect_any_instance_of(Image).to receive(:save).with(tmpdir, "201405091845").once
38
- client.download_image(tmpdir)
39
- end
40
-
41
- it "should log the result" do
42
- expect(logger).to receive(:info).with("Downloaded: 201405091845.jpg")
43
- client.download_image(tmpdir)
47
+ context "when valid minute is specified" do
48
+ let(:minute) do
49
+ 30
44
50
  end
45
- end
46
51
 
47
- context "when valid minute is specified" do
48
52
  it "should download the image of the specified minutes ago" do
49
- expect_any_instance_of(Image).to receive(:save).with(tmpdir, "201405091815").once
50
- client.download_image(tmpdir, 30)
53
+ expect_any_instance_of(Image).to receive(:save).with(tmpdir, "201405091815.jpg").once
54
+ download_image
51
55
  end
52
56
 
53
57
  it "should log the result" do
54
58
  expect(logger).to receive(:info).with("Downloaded: 201405091815.jpg")
55
- client.download_image(tmpdir, 30)
59
+ download_image
56
60
  end
57
61
  end
58
62
 
59
63
  context "when invalid minute is specified" do
64
+ let(:minute) do
65
+ 7
66
+ end
67
+
60
68
  it "should raise ArgumentError" do
61
69
  expect do
62
- client.download_image(tmpdir, 7)
70
+ download_image
63
71
  end.to raise_error ArgumentError
64
72
  end
65
73
  end
74
+
75
+ context "when filename is specified" do
76
+ let(:filename) do
77
+ "out.jpg"
78
+ end
79
+
80
+ it "should download the image with specified name" do
81
+ expect_any_instance_of(Image).to receive(:save).with(tmpdir, "out.jpg").once
82
+ download_image
83
+ end
84
+ end
66
85
  end
67
86
 
68
87
  describe "#download_sequential_images" do
88
+ let(:download_sequential_images) do
89
+ client.download_sequential_images(from, to, tmpdir)
90
+ end
91
+
69
92
  context "when valid section is specified" do
93
+ let(:from) do
94
+ 0
95
+ end
96
+
97
+ let(:to) do
98
+ 30
99
+ end
100
+
70
101
  it "should download the images" do
71
102
  expect_any_instance_of(Client).to receive(:download_image).exactly(7).times
72
- client.download_sequential_images(tmpdir, 0, 30)
103
+ download_sequential_images
73
104
  end
74
105
  end
75
106
 
76
107
  context "when invalid section is specified" do
108
+ let(:from) do
109
+ 1
110
+ end
111
+
112
+ let(:to) do
113
+ 2
114
+ end
115
+
77
116
  it "should raise ArgumentError" do
78
117
  expect do
79
- client.download_sequential_images(tmpdir, 1, 2)
118
+ download_sequential_images
80
119
  end.to raise_error ArgumentError
81
120
  end
82
121
  end
@@ -7,6 +7,10 @@ module Ramesh
7
7
  "201405091845"
8
8
  end
9
9
 
10
+ let(:filename) do
11
+ "201405091845.jpg"
12
+ end
13
+
10
14
  let(:tmpdir) do
11
15
  File.expand_path(File.join("..", "..", "tmp"), __FILE__)
12
16
  end
@@ -81,8 +85,8 @@ module Ramesh
81
85
 
82
86
  it "should save itself to the file" do
83
87
  image = described_class.new(image_name)
84
- image.save(tmpdir, image_name)
85
- expect(File.exist?(File.join(tmpdir, "#{image_name}.jpg"))).to be_truthy
88
+ image.save(tmpdir, filename)
89
+ expect(File.exist?(File.join(tmpdir, filename))).to be_truthy
86
90
  end
87
91
 
88
92
  after do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ramesh
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - dtan4
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-01 00:00:00.000000000 Z
11
+ date: 2014-07-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -198,4 +198,3 @@ test_files:
198
198
  - spec/ramesh/logger_spec.rb
199
199
  - spec/ramesh_spec.rb
200
200
  - spec/spec_helper.rb
201
- has_rdoc: