ramesh 1.3.0 → 1.4.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: 70c9be78a66d6d02b4a882874ff795aaa5fd13d0
4
- data.tar.gz: b057347aca5b9b104358c8e810d08e70cbdd08cd
3
+ metadata.gz: e5fa370a619fa4dbf3f126a9f13cbc8c062fe3ef
4
+ data.tar.gz: 8a6916677ea79e183a31e5068407b84364eb358d
5
5
  SHA512:
6
- metadata.gz: bfcd3e5df4f56bc52571c983bf2c296dbee2896eb33089a852353aa77161420ee3a57a17b2707323533976e8e86d71a1d204bb221cfc774dae229e9222899851
7
- data.tar.gz: fde72af13834220b9ad77f62486fed6d8d6a9fbf9733545e37707825dea0bcb6bab8f266f6ab62b81cd7bb4b4bbc0c1abfa5226fcd89f50abe8e58be68a34889
6
+ metadata.gz: 26720dcf58e153f7875c73a03e009fee628637f82d5870c30efff8f7115c9d4db1913accc6eb272e697a53444cf890c6e93ce2a12545291930ebdfa0a63583f0
7
+ data.tar.gz: 92ddd4a170341d856df17dba06998d342279765775640dc51b4ee5c9639d9b43baa120d8133675a157201fa37c40eb73f542caad0caae63dd171c60762b2f1a6
@@ -1,5 +1,8 @@
1
1
  language: ruby
2
+ addons:
3
+ code_climate:
4
+ repo_token: oshGwJLUmoVW4rxGVlfgutKzrSW3arKW6xxqEH99r74Tva6VlxTmjmL/H9z2Erf4POMi0kqRh1b8brGGb48oVFRc3xOCX8EM/4rchgdSK38/Ue+MOffsYTyqXFY0fYF8rwbsYssAPsFd+3BsdmJ2uOBWtHil4nRxxm2ixxNAZgU=
2
5
  rvm:
3
- - 1.9.3
4
6
  - 2.0.0
5
- - 2.1
7
+ - 2.1.5
8
+ - 2.2
data/Guardfile CHANGED
@@ -1,7 +1,7 @@
1
1
  # A sample Guardfile
2
2
  # More info at https://github.com/guard/guard#readme
3
3
 
4
- guard :rspec do
4
+ guard :rspec, cmd: "bundle exec rspec" do
5
5
  watch(%r{^spec/.+_spec\.rb$})
6
6
  watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
7
7
  watch('spec/spec_helper.rb') { "spec" }
data/bin/ramesh CHANGED
@@ -13,23 +13,33 @@ EOS
13
13
 
14
14
  save_dir = Dir.pwd
15
15
  filename = nil
16
+ large_image = false
16
17
 
17
18
  parser = OptionParser.new(USAGE) do |opt|
18
19
  opt.on("-d", "--dir=VAL", "Save directory (default: current directory)") { |val| save_dir = val }
19
20
  opt.on("-f", "--filename=VAL", "Save file name (default: timestamp index of downloaded image)") { |val| filename = val }
21
+ opt.on("-l", "--large", "Download large image") { |large| large_image = large }
20
22
  end
21
23
 
22
24
  argv = parser.parse(ARGV)
23
25
 
24
- client = Ramesh::Client.new(Ramesh::Logger.new(STDOUT))
26
+ client = Ramesh::Client.new
25
27
 
26
28
  case argv.length
27
29
  when 0
28
- client.download_image(0, save_dir, filename)
30
+ if large_image
31
+ puts client.download_large_image(0, save_dir, filename)
32
+ else
33
+ puts client.download_image(0, save_dir, filename)
34
+ end
29
35
  when 1
30
- client.download_image(argv[0].to_i, save_dir, filename)
36
+ if large_image
37
+ puts client.download_large_image(argv[0].to_i, save_dir, filename)
38
+ else
39
+ puts client.download_image(argv[0].to_i, save_dir, filename)
40
+ end
31
41
  when 2
32
- client.download_sequential_images(argv[0].to_i, argv[1].to_i, save_dir)
42
+ puts client.download_sequential_images(argv[0].to_i, argv[1].to_i, save_dir).join(", ")
33
43
  else
34
44
  $stderr.puts USAGE
35
45
  exit 1
@@ -1,4 +1,3 @@
1
1
  require "ramesh/client"
2
2
  require "ramesh/image"
3
- require "ramesh/logger"
4
3
  require "ramesh/version"
@@ -2,35 +2,35 @@ module Ramesh
2
2
  class Client
3
3
  MESHES_INDEX_URL = "http://tokyo-ame.jwa.or.jp/scripts/mesh_index.js"
4
4
 
5
- def initialize(logger)
6
- @logger = logger
7
- end
8
-
9
5
  def download_image(minute, save_dir, filename = nil)
10
- unless valid_minutes?(minute)
11
- raise ArgumentError, "minutes must be a number; 0, 5, 10, ... 120"
12
- end
13
-
14
- image_name = name_from_minute(minute)
15
- filename ||= "#{image_name}.jpg"
16
- image = Image.new(image_name, background_image, mask_image)
17
- image.save(save_dir, filename)
6
+ _download_image(minute, save_dir, filename, :small)
7
+ end
18
8
 
19
- @logger.info("Downloaded: #{filename}")
9
+ def download_large_image(minute, save_dir, filename = nil)
10
+ _download_image(minute, save_dir, filename, :large)
20
11
  end
21
12
 
22
13
  def download_sequential_images(from, to, save_dir)
23
- unless valid_minutes?(from) && valid_minutes?(to)
24
- raise ArgumentError, "minutes must be a number; 0, 5, 10, ... 120"
25
- end
14
+ raise ArgumentError, "minutes must be a number; 0, 5, 10, ... 120" unless valid_minutes?(from) && valid_minutes?(to)
26
15
 
27
- (from..to).step(5) do |minute|
28
- download_image(save_dir, minute)
16
+ [].tap do |image_names|
17
+ (from..to).step(5) { |minute| image_names << download_image(minute, save_dir) }
29
18
  end
30
19
  end
31
20
 
32
21
  private
33
22
 
23
+ def _download_image(minute, save_dir, filename, image_size)
24
+ raise ArgumentError, "minutes must be a number; 0, 5, 10, ... 120" unless valid_minutes?(minute)
25
+
26
+ image_name = name_from_minute(minute)
27
+ filename ||= "#{image_name}.jpg"
28
+ image = Image.new(image_name, image_size)
29
+ image.save(save_dir, filename)
30
+
31
+ filename
32
+ end
33
+
34
34
  def background_image
35
35
  @background_image ||= Image.background_image
36
36
  end
@@ -3,25 +3,14 @@ require "open-uri"
3
3
 
4
4
  module Ramesh
5
5
  class Image
6
- MESH_URL_BASE = "http://tokyo-ame.jwa.or.jp/mesh/000/"
7
- BACKGROUND_IMAGE_URL = "http://tokyo-ame.jwa.or.jp/map/map000.jpg"
8
- MASK_IMAGE_URL = "http://tokyo-ame.jwa.or.jp/map/msk000.png"
6
+ MESH_URL_BASE = "http://tokyo-ame.jwa.or.jp/mesh"
7
+ MAP_URL_BASE = "http://tokyo-ame.jwa.or.jp/map"
9
8
 
10
- def self.background_image
11
- download_image(BACKGROUND_IMAGE_URL)
12
- end
13
-
14
- def self.mask_image
15
- download_image(MASK_IMAGE_URL)
16
- end
17
-
18
- def initialize(image_name,
19
- background_image = self.class.background_image,
20
- mask_image = self.class.mask_image)
9
+ def initialize(image_name, image_size = :small)
21
10
  image_list = [
22
- background_image,
23
- self.class.download_image(moment_image_url(image_name)),
24
- mask_image
11
+ background_image(image_size),
12
+ moment_image(image_name, image_size),
13
+ mask_image(image_size)
25
14
  ]
26
15
  @image = composite_images(image_list)
27
16
  end
@@ -33,12 +22,43 @@ module Ramesh
33
22
 
34
23
  private
35
24
 
36
- def self.download_image(url)
25
+ def background_image(image_size)
26
+ download_image(background_image_url(image_size))
27
+ end
28
+
29
+ def moment_image(image_name, image_size)
30
+ download_image(moment_image_url(image_name, image_size))
31
+ end
32
+
33
+ def mask_image(image_size)
34
+ download_image(mask_image_url(image_size))
35
+ end
36
+
37
+ def download_image(url)
37
38
  MiniMagick::Image.read(open(url).read)
38
39
  end
39
40
 
40
- def moment_image_url(image_name)
41
- "#{MESH_URL_BASE}#{image_name}.gif"
41
+ def size_number(image_size)
42
+ case image_size
43
+ when :small
44
+ "000"
45
+ when :large
46
+ "100"
47
+ else
48
+ raise ArgumentError, "Invalid size is given"
49
+ end
50
+ end
51
+
52
+ def background_image_url(image_size)
53
+ "#{MAP_URL_BASE}/map#{size_number(image_size)}.jpg"
54
+ end
55
+
56
+ def moment_image_url(image_name, image_size)
57
+ "#{MESH_URL_BASE}/#{size_number(image_size)}/#{image_name}.gif"
58
+ end
59
+
60
+ def mask_image_url(image_size)
61
+ "#{MAP_URL_BASE}/msk#{size_number(image_size)}.png"
42
62
  end
43
63
 
44
64
  def composite_images(image_list)
@@ -1,3 +1,3 @@
1
1
  module Ramesh
2
- VERSION = "1.3.0"
2
+ VERSION = "1.4.0"
3
3
  end
@@ -19,7 +19,7 @@ Gem::Specification.new do |spec|
19
19
  spec.require_paths = ["lib"]
20
20
 
21
21
  spec.add_development_dependency "bundler", "~> 1.3"
22
- spec.add_development_dependency "coveralls"
22
+ spec.add_development_dependency "codeclimate-test-reporter"
23
23
  spec.add_development_dependency "fakefs"
24
24
  spec.add_development_dependency "guard-rspec"
25
25
  spec.add_development_dependency "rake"
@@ -3,21 +3,9 @@ require "fileutils"
3
3
 
4
4
  module Ramesh
5
5
  describe Client do
6
- let(:logger) do
7
- double("logger", info: true)
8
- end
9
-
10
- let(:client) do
11
- Ramesh::Client.new(logger)
12
- end
13
-
14
- let(:tmpdir) do
15
- File.expand_path(File.join("..", "..", "tmp"), __FILE__)
16
- end
17
-
18
- let(:meshes_index_url) do
19
- "http://tokyo-ame.jwa.or.jp/scripts/mesh_index.js"
20
- end
6
+ let(:client) { Ramesh::Client.new }
7
+ let(:tmpdir) { File.expand_path(File.join("..", "..", "tmp"), __FILE__) }
8
+ let(:meshes_index_url) { "http://tokyo-ame.jwa.or.jp/scripts/mesh_index.js" }
21
9
 
22
10
  before do
23
11
  stub_request(:get, meshes_index_url)
@@ -26,21 +14,13 @@ module Ramesh
26
14
  end
27
15
 
28
16
  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
17
+ let(:download_image) { client.download_image(minute, tmpdir, filename) }
18
+ let(:minute) { 0 }
19
+ let(:filename) { nil }
40
20
 
41
21
  before do
42
22
  image = double(write: true)
43
- allow(Image).to receive(:download_image).and_return(image)
23
+ allow_any_instance_of(Image).to receive(:download_image).and_return(image)
44
24
  allow_any_instance_of(Image).to receive(:composite_images).and_return(image)
45
25
  end
46
26
 
@@ -49,13 +29,12 @@ module Ramesh
49
29
  30
50
30
  end
51
31
 
52
- it "should download the image of the specified minutes ago" do
53
- expect_any_instance_of(Image).to receive(:save).with(tmpdir, "201405091815.jpg").once
54
- download_image
32
+ it "should return image name" do
33
+ expect(download_image).to eq "201405091815.jpg"
55
34
  end
56
35
 
57
- it "should log the result" do
58
- expect(logger).to receive(:info).with("Downloaded: 201405091815.jpg")
36
+ it "should download the image of the specified minutes ago" do
37
+ expect_any_instance_of(Image).to receive(:save).with(tmpdir, "201405091815.jpg").once
59
38
  download_image
60
39
  end
61
40
  end
@@ -77,6 +56,10 @@ module Ramesh
77
56
  "out.jpg"
78
57
  end
79
58
 
59
+ it "should return image name" do
60
+ expect(download_image).to eq filename
61
+ end
62
+
80
63
  it "should download the image with specified name" do
81
64
  expect_any_instance_of(Image).to receive(:save).with(tmpdir, "out.jpg").once
82
65
  download_image
@@ -84,18 +67,71 @@ module Ramesh
84
67
  end
85
68
  end
86
69
 
70
+ describe "#download_large_image" do
71
+ let(:download_large_image) { client.download_large_image(minute, tmpdir, filename) }
72
+ let(:minute) { 0 }
73
+ let(:filename) { nil }
74
+
75
+ before do
76
+ image = double(write: true)
77
+ allow_any_instance_of(Image).to receive(:download_image).and_return(image)
78
+ allow_any_instance_of(Image).to receive(:composite_images).and_return(image)
79
+ end
80
+
81
+ context "when valid minute is specified" do
82
+ let(:minute) { 30 }
83
+
84
+ it "should return image name" do
85
+ expect(download_large_image).to eq "201405091815.jpg"
86
+ end
87
+
88
+ it "should download the image of the specified minutes ago" do
89
+ expect_any_instance_of(Image).to receive(:save).with(tmpdir, "201405091815.jpg").once
90
+ download_large_image
91
+ end
92
+ end
93
+
94
+ context "when invalid minute is specified" do
95
+ let(:minute) { 7 }
96
+
97
+ it "should raise ArgumentError" do
98
+ expect do
99
+ download_large_image
100
+ end.to raise_error ArgumentError
101
+ end
102
+ end
103
+
104
+ context "when filename is specified" do
105
+ let(:filename) { "out.jpg" }
106
+
107
+ it "should return image name" do
108
+ expect(download_large_image).to eq filename
109
+ end
110
+
111
+ it "should download the image with specified name" do
112
+ expect_any_instance_of(Image).to receive(:save).with(tmpdir, "out.jpg").once
113
+ download_large_image
114
+ end
115
+ end
116
+ end
117
+
87
118
  describe "#download_sequential_images" do
88
- let(:download_sequential_images) do
89
- client.download_sequential_images(from, to, tmpdir)
119
+ let(:download_sequential_images) { client.download_sequential_images(from, to, tmpdir) }
120
+
121
+ before do
122
+ image = double(write: true)
123
+ allow_any_instance_of(Image).to receive(:download_image).and_return(image)
124
+ allow_any_instance_of(Image).to receive(:composite_images).and_return(image)
90
125
  end
91
126
 
92
127
  context "when valid section is specified" do
93
- let(:from) do
94
- 0
95
- end
128
+ let(:from) { 0 }
129
+ let(:to) { 30 }
96
130
 
97
- let(:to) do
98
- 30
131
+ it "should return the array of image names" do
132
+ result = download_sequential_images
133
+ expect(result).to be_a Array
134
+ expect(result.length).to eq 7
99
135
  end
100
136
 
101
137
  it "should download the images" do
@@ -105,13 +141,8 @@ module Ramesh
105
141
  end
106
142
 
107
143
  context "when invalid section is specified" do
108
- let(:from) do
109
- 1
110
- end
111
-
112
- let(:to) do
113
- 2
114
- end
144
+ let(:from) { 1 }
145
+ let(:to) { 2 }
115
146
 
116
147
  it "should raise ArgumentError" do
117
148
  expect do
@@ -3,30 +3,34 @@ require "fileutils"
3
3
 
4
4
  module Ramesh
5
5
  describe Image do
6
- let(:image_name) do
7
- "201405091845"
8
- end
9
-
10
- let(:filename) do
11
- "201405091845.jpg"
12
- end
13
-
14
- let(:tmpdir) do
15
- File.expand_path(File.join("..", "..", "tmp"), __FILE__)
16
- end
6
+ let(:image_name) { "201405091845" }
7
+ let(:filename) { "201405091845.jpg" }
8
+ let(:tmpdir) { File.expand_path(File.join("..", "..", "tmp"), __FILE__) }
17
9
 
18
10
  let(:mesh_url) do
19
11
  "http://tokyo-ame.jwa.or.jp/mesh/000/#{image_name}.gif"
20
12
  end
21
13
 
14
+ let(:mesh_url_large) do
15
+ "http://tokyo-ame.jwa.or.jp/mesh/100/#{image_name}.gif"
16
+ end
17
+
22
18
  let(:background_url) do
23
19
  "http://tokyo-ame.jwa.or.jp/map/map000.jpg"
24
20
  end
25
21
 
22
+ let(:background_url_large) do
23
+ "http://tokyo-ame.jwa.or.jp/map/map100.jpg"
24
+ end
25
+
26
26
  let(:mask_url) do
27
27
  "http://tokyo-ame.jwa.or.jp/map/msk000.png"
28
28
  end
29
29
 
30
+ let(:mask_url_large) do
31
+ "http://tokyo-ame.jwa.or.jp/map/msk100.png"
32
+ end
33
+
30
34
  let(:fixture_image) do
31
35
  open(fixture_path("lena.png")).read
32
36
  end
@@ -34,24 +38,16 @@ module Ramesh
34
38
  before do
35
39
  stub_request(:get, mesh_url)
36
40
  .to_return(status: 200, body: fixture_image)
41
+ stub_request(:get, mesh_url_large)
42
+ .to_return(status: 200, body: fixture_image)
37
43
  stub_request(:get, background_url)
38
44
  .to_return(status: 200, body: fixture_image)
45
+ stub_request(:get, background_url_large)
46
+ .to_return(status: 200, body: fixture_image)
39
47
  stub_request(:get, mask_url)
40
48
  .to_return(status: 200, body: fixture_image)
41
- end
42
-
43
- describe "#background_image" do
44
- it "should download the background image" do
45
- described_class.background_image
46
- expect(a_request(:get, background_url)).to have_been_made.once
47
- end
48
- end
49
-
50
- describe "#mask_image" do
51
- it "should download the mask image" do
52
- described_class.mask_image
53
- expect(a_request(:get, mask_url)).to have_been_made.once
54
- end
49
+ stub_request(:get, mask_url_large)
50
+ .to_return(status: 200, body: fixture_image)
55
51
  end
56
52
 
57
53
  describe "#initialize" do
@@ -63,19 +59,6 @@ module Ramesh
63
59
  expect(a_request(:get, mask_url)).to have_been_made.once
64
60
  end
65
61
  end
66
-
67
- context "with cached images" do
68
- it "should composite the moment image" do
69
- image = double(composite: true)
70
- background_image = double(composite: image)
71
- mask_image = double(composite: image)
72
-
73
- described_class.new(image_name, background_image, mask_image)
74
- expect(a_request(:get, mesh_url)).to have_been_made.once
75
- expect(a_request(:get, background_url)).not_to have_been_made
76
- expect(a_request(:get, mask_url)).not_to have_been_made
77
- end
78
- end
79
62
  end
80
63
 
81
64
  describe "#save" do
@@ -1,11 +1,13 @@
1
- require 'coveralls'
2
- Coveralls.wear!
1
+ require 'codeclimate-test-reporter'
2
+ CodeClimate::TestReporter.start
3
3
 
4
4
  $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
5
5
 
6
6
  require 'ramesh'
7
7
  require 'webmock/rspec'
8
8
 
9
+ WebMock.disable_net_connect!(allow: "codeclimate.com")
10
+
9
11
  def fixture_path(name)
10
12
  File.expand_path(File.join("..", "fixtures", name), __FILE__)
11
13
  end
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.3.0
4
+ version: 1.4.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-04 00:00:00.000000000 Z
11
+ date: 2014-11-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -25,7 +25,7 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.3'
27
27
  - !ruby/object:Gem::Dependency
28
- name: coveralls
28
+ name: codeclimate-test-reporter
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
@@ -156,14 +156,12 @@ files:
156
156
  - lib/ramesh.rb
157
157
  - lib/ramesh/client.rb
158
158
  - lib/ramesh/image.rb
159
- - lib/ramesh/logger.rb
160
159
  - lib/ramesh/version.rb
161
160
  - ramesh.gemspec
162
161
  - spec/fixtures/index.js
163
162
  - spec/fixtures/lena.png
164
163
  - spec/ramesh/client_spec.rb
165
164
  - spec/ramesh/image_spec.rb
166
- - spec/ramesh/logger_spec.rb
167
165
  - spec/ramesh_spec.rb
168
166
  - spec/spec_helper.rb
169
167
  homepage: https://github.com/dtan4/ramesh
@@ -195,6 +193,5 @@ test_files:
195
193
  - spec/fixtures/lena.png
196
194
  - spec/ramesh/client_spec.rb
197
195
  - spec/ramesh/image_spec.rb
198
- - spec/ramesh/logger_spec.rb
199
196
  - spec/ramesh_spec.rb
200
197
  - spec/spec_helper.rb
@@ -1,11 +0,0 @@
1
- module Ramesh
2
- class Logger
3
- def initialize(output)
4
- @output = output
5
- end
6
-
7
- def info(msg)
8
- @output.puts msg
9
- end
10
- end
11
- end
@@ -1,20 +0,0 @@
1
- require "spec_helper"
2
-
3
- module Ramesh
4
- describe Logger do
5
- let(:output) do
6
- double("output", puts: true)
7
- end
8
-
9
- let(:logger) do
10
- described_class.new(output)
11
- end
12
-
13
- describe "#info" do
14
- it "should flush message" do
15
- logger.info("message")
16
- expect(output).to have_received(:puts).with("message")
17
- end
18
- end
19
- end
20
- end