Skip to content
This repository has been archived by the owner on Jul 13, 2023. It is now read-only.

Commit

Permalink
Don't use Factory in the name. It's tacky.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon Yurek committed Nov 16, 2012
1 parent 8338024 commit 233fcb9
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 17 deletions.
6 changes: 3 additions & 3 deletions lib/paperclip/geometry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module Paperclip

# Defines the geometry of an image.
class Geometry
attr_accessor :height, :width, :modifier, :orientation
attr_accessor :height, :width, :modifier

EXIF_ROTATED_ORIENTATION_VALUES = [5, 6, 7, 8]

Expand All @@ -23,14 +23,14 @@ def initialize(width = nil, height = nil, modifier = nil)

# Extracts the Geometry from a file (or path to a file)
def self.from_file(file)
GeometryDetectorFactory.new(file).make
GeometryDetector.new(file).make
end

# Extracts the Geometry from a "WxH,O" string
# Where W is the width, H is the height,
# and O is the EXIF orientation
def self.parse(string)
GeometryParserFactory.new(string).make
GeometryParser.new(string).make
end

# Swaps the height and width if necessary
Expand Down
4 changes: 2 additions & 2 deletions lib/paperclip/geometry_detector_factory.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
module Paperclip
class GeometryDetectorFactory
class GeometryDetector
def initialize(file)
@file = file
raise_if_blank_file
end

def make
GeometryParserFactory.new(geometry_string.strip).make ||
GeometryParser.new(geometry_string.strip).make ||
raise(Errors::NotIdentifiedByImageMagickError.new)
end

Expand Down
2 changes: 1 addition & 1 deletion lib/paperclip/geometry_parser_factory.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Paperclip
class GeometryParserFactory
class GeometryParser
FORMAT = /\b(\d*)x?(\d*)\b(?:,(\d?))?([\>\<\#\@\%^!])?/i
def initialize(string)
@string = string
Expand Down
10 changes: 5 additions & 5 deletions test/geometry_detector_factory_test.rb
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
require './test/helper'

class GeometryDetectorFactoryTest < Test::Unit::TestCase
class GeometryDetectorTest < Test::Unit::TestCase
should 'identify an image and extract its dimensions' do
Paperclip::GeometryParserFactory.stubs(:new).with("434x66,").returns(stub(:make => :correct))
Paperclip::GeometryParser.stubs(:new).with("434x66,").returns(stub(:make => :correct))
file = fixture_file("5k.png")
factory = Paperclip::GeometryDetectorFactory.new(file)
factory = Paperclip::GeometryDetector.new(file)

output = factory.make

assert_equal :correct, output
end

should 'identify an image and extract its dimensions and orientation' do
Paperclip::GeometryParserFactory.stubs(:new).with("300x200,6").returns(stub(:make => :correct))
Paperclip::GeometryParser.stubs(:new).with("300x200,6").returns(stub(:make => :correct))
file = fixture_file("rotated.jpg")
factory = Paperclip::GeometryDetectorFactory.new(file)
factory = Paperclip::GeometryDetector.new(file)

output = factory.make

Expand Down
12 changes: 6 additions & 6 deletions test/geometry_parser_factory_test.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
require './test/helper'

class GeometryParserFactoryTest < Test::Unit::TestCase
class GeometryParserTest < Test::Unit::TestCase
should 'identify an image and extract its dimensions with no orientation' do
Paperclip::Geometry.stubs(:new).with(
:height => '73',
:width => '434',
:modifier => nil,
:orientation => nil
).returns(:correct)
factory = Paperclip::GeometryParserFactory.new("434x73")
factory = Paperclip::GeometryParser.new("434x73")

output = factory.make

Expand All @@ -22,7 +22,7 @@ class GeometryParserFactoryTest < Test::Unit::TestCase
:modifier => nil,
:orientation => ''
).returns(:correct)
factory = Paperclip::GeometryParserFactory.new("434x73,")
factory = Paperclip::GeometryParser.new("434x73,")

output = factory.make

Expand All @@ -36,7 +36,7 @@ class GeometryParserFactoryTest < Test::Unit::TestCase
:modifier => nil,
:orientation => '6'
).returns(:correct)
factory = Paperclip::GeometryParserFactory.new("300x200,6")
factory = Paperclip::GeometryParser.new("300x200,6")

output = factory.make

Expand All @@ -50,7 +50,7 @@ class GeometryParserFactoryTest < Test::Unit::TestCase
:modifier => '#',
:orientation => nil
).returns(:correct)
factory = Paperclip::GeometryParserFactory.new("64x64#")
factory = Paperclip::GeometryParser.new("64x64#")

output = factory.make

Expand All @@ -64,7 +64,7 @@ class GeometryParserFactoryTest < Test::Unit::TestCase
:modifier => '>',
:orientation => '7'
).returns(:correct)
factory = Paperclip::GeometryParserFactory.new("100x50,7>")
factory = Paperclip::GeometryParser.new("100x50,7>")

output = factory.make

Expand Down

0 comments on commit 233fcb9

Please sign in to comment.