Skip to content
This repository has been archived by the owner on Jan 6, 2018. It is now read-only.

Commit

Permalink
Makes more sense to have image iterator simply provide functionality …
Browse files Browse the repository at this point in the history
…as a module..
  • Loading branch information
stefanpenner committed Feb 12, 2012
1 parent 3397cf6 commit cca77a3
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 19 deletions.
11 changes: 0 additions & 11 deletions actions/image.rb
Expand Up @@ -7,17 +7,6 @@ module Actions
class Image
AnnotationException = Class.new(Exception)

module Didntfindshit

def file
File.new './public/didntfindshit.jpg'
end

def max_age
30
end
end

attr_accessor :file, :max_age

def initialize(noun)
Expand Down
1 change: 1 addition & 0 deletions sources/bing.rb
Expand Up @@ -4,6 +4,7 @@

class Bing
attr_reader :noun, :images, :result, :json
include ImageIterator

def initialize(noun)
@noun = noun
Expand Down
11 changes: 5 additions & 6 deletions sources/image_iterator.rb
@@ -1,14 +1,13 @@
class ImageIterator
def initialize(urls=[])
@urls = urls
@enum = @urls.to_enum
module ImageIterator
def enum
@enum ||= @images.to_enum
end

def next
Kernel.open(@enum.next)
Kernel.open(enum.next)
end

def rewind
@enum.rewind
enum.rewind
end
end
2 changes: 1 addition & 1 deletion spec/sources/bing_spec.rb
Expand Up @@ -28,7 +28,7 @@

let(:subject) { Bing.fetch('xbox') }
its(:images) { should respond_to(:each) }
its(:images) { should ==(['http://example.com/example.jpg'])}
its(:images) { should == ['http://example.com/example.jpg'] }

its('best_image.path') { should == './spec/support/test_image.jpg' }
end
Expand Down
11 changes: 10 additions & 1 deletion spec/sources/image_iterator_spec.rb
@@ -1,12 +1,21 @@
require './sources/image_iterator'

class Dummy
include ImageIterator
attr_accessor :images

def initialize(images=[])
@images = images
end
end

describe 'ImageIterator' do
context 'basic' do
before do
Kernel.stub(:open) { |arg| arg }
end

subject { ImageIterator.new([:a,:b,:c]) }
subject { Dummy.new([:a,:b,:c]) }

it 'iterates as expected' do
subject.next.should == :a
Expand Down

0 comments on commit cca77a3

Please sign in to comment.