ramesh 1.2.0 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/bin/ramesh +9 -7
- data/lib/ramesh/client.rb +5 -4
- data/lib/ramesh/image.rb +2 -2
- data/lib/ramesh/version.rb +1 -1
- data/spec/ramesh/client_spec.rb +56 -17
- data/spec/ramesh/image_spec.rb +6 -2
- metadata +2 -3
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 70c9be78a66d6d02b4a882874ff795aaa5fd13d0
         | 
| 4 | 
            +
              data.tar.gz: b057347aca5b9b104358c8e810d08e70cbdd08cd
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 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] | 
| 9 | 
            -
                ramesh [-d save_dir] 0 | 
| 10 | 
            -
                ramesh [-d save_dir] 0 | 
| 11 | 
            -
                ramesh -h, --help | 
| 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( | 
| 30 | 
            +
              client.download_image(argv[0].to_i, save_dir, filename)
         | 
| 29 31 | 
             
            when 2
         | 
| 30 | 
            -
              client.download_sequential_images( | 
| 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
         | 
    
        data/lib/ramesh/client.rb
    CHANGED
    
    | @@ -6,19 +6,20 @@ module Ramesh | |
| 6 6 | 
             
                  @logger = logger
         | 
| 7 7 | 
             
                end
         | 
| 8 8 |  | 
| 9 | 
            -
                def download_image(save_dir,  | 
| 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,  | 
| 17 | 
            +
                  image.save(save_dir, filename)
         | 
| 17 18 |  | 
| 18 | 
            -
                  @logger.info("Downloaded: #{ | 
| 19 | 
            +
                  @logger.info("Downloaded: #{filename}")
         | 
| 19 20 | 
             
                end
         | 
| 20 21 |  | 
| 21 | 
            -
                def download_sequential_images( | 
| 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
         | 
    
        data/lib/ramesh/image.rb
    CHANGED
    
    | @@ -26,8 +26,8 @@ module Ramesh | |
| 26 26 | 
             
                  @image = composite_images(image_list)
         | 
| 27 27 | 
             
                end
         | 
| 28 28 |  | 
| 29 | 
            -
                def save(save_dir,  | 
| 30 | 
            -
                  save_path = File.join(save_dir,  | 
| 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 |  | 
    
        data/lib/ramesh/version.rb
    CHANGED
    
    
    
        data/spec/ramesh/client_spec.rb
    CHANGED
    
    | @@ -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  | 
| 36 | 
            -
                     | 
| 37 | 
            -
                       | 
| 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 | 
            -
                       | 
| 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 | 
            -
                       | 
| 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 | 
            -
                         | 
| 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 | 
            -
                       | 
| 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 | 
            -
                         | 
| 118 | 
            +
                        download_sequential_images
         | 
| 80 119 | 
             
                      end.to raise_error ArgumentError
         | 
| 81 120 | 
             
                    end
         | 
| 82 121 | 
             
                  end
         | 
    
        data/spec/ramesh/image_spec.rb
    CHANGED
    
    | @@ -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,  | 
| 85 | 
            -
                    expect(File.exist?(File.join(tmpdir,  | 
| 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. | 
| 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- | 
| 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: 
         |