Commit 233fcb90 by Jon Yurek

Don't use Factory in the name. It's tacky.

parent 8338024a
...@@ -2,7 +2,7 @@ module Paperclip ...@@ -2,7 +2,7 @@ module Paperclip
# Defines the geometry of an image. # Defines the geometry of an image.
class Geometry class Geometry
attr_accessor :height, :width, :modifier, :orientation attr_accessor :height, :width, :modifier
EXIF_ROTATED_ORIENTATION_VALUES = [5, 6, 7, 8] EXIF_ROTATED_ORIENTATION_VALUES = [5, 6, 7, 8]
...@@ -23,14 +23,14 @@ module Paperclip ...@@ -23,14 +23,14 @@ module Paperclip
# Extracts the Geometry from a file (or path to a file) # Extracts the Geometry from a file (or path to a file)
def self.from_file(file) def self.from_file(file)
GeometryDetectorFactory.new(file).make GeometryDetector.new(file).make
end end
# Extracts the Geometry from a "WxH,O" string # Extracts the Geometry from a "WxH,O" string
# Where W is the width, H is the height, # Where W is the width, H is the height,
# and O is the EXIF orientation # and O is the EXIF orientation
def self.parse(string) def self.parse(string)
GeometryParserFactory.new(string).make GeometryParser.new(string).make
end end
# Swaps the height and width if necessary # Swaps the height and width if necessary
......
module Paperclip module Paperclip
class GeometryDetectorFactory class GeometryDetector
def initialize(file) def initialize(file)
@file = file @file = file
raise_if_blank_file raise_if_blank_file
end end
def make def make
GeometryParserFactory.new(geometry_string.strip).make || GeometryParser.new(geometry_string.strip).make ||
raise(Errors::NotIdentifiedByImageMagickError.new) raise(Errors::NotIdentifiedByImageMagickError.new)
end end
......
module Paperclip module Paperclip
class GeometryParserFactory class GeometryParser
FORMAT = /\b(\d*)x?(\d*)\b(?:,(\d?))?([\>\<\#\@\%^!])?/i FORMAT = /\b(\d*)x?(\d*)\b(?:,(\d?))?([\>\<\#\@\%^!])?/i
def initialize(string) def initialize(string)
@string = string @string = string
......
require './test/helper' require './test/helper'
class GeometryDetectorFactoryTest < Test::Unit::TestCase class GeometryDetectorTest < Test::Unit::TestCase
should 'identify an image and extract its dimensions' do 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") file = fixture_file("5k.png")
factory = Paperclip::GeometryDetectorFactory.new(file) factory = Paperclip::GeometryDetector.new(file)
output = factory.make output = factory.make
...@@ -12,9 +12,9 @@ class GeometryDetectorFactoryTest < Test::Unit::TestCase ...@@ -12,9 +12,9 @@ class GeometryDetectorFactoryTest < Test::Unit::TestCase
end end
should 'identify an image and extract its dimensions and orientation' do 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") file = fixture_file("rotated.jpg")
factory = Paperclip::GeometryDetectorFactory.new(file) factory = Paperclip::GeometryDetector.new(file)
output = factory.make output = factory.make
......
require './test/helper' 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 should 'identify an image and extract its dimensions with no orientation' do
Paperclip::Geometry.stubs(:new).with( Paperclip::Geometry.stubs(:new).with(
:height => '73', :height => '73',
...@@ -8,7 +8,7 @@ class GeometryParserFactoryTest < Test::Unit::TestCase ...@@ -8,7 +8,7 @@ class GeometryParserFactoryTest < Test::Unit::TestCase
:modifier => nil, :modifier => nil,
:orientation => nil :orientation => nil
).returns(:correct) ).returns(:correct)
factory = Paperclip::GeometryParserFactory.new("434x73") factory = Paperclip::GeometryParser.new("434x73")
output = factory.make output = factory.make
...@@ -22,7 +22,7 @@ class GeometryParserFactoryTest < Test::Unit::TestCase ...@@ -22,7 +22,7 @@ class GeometryParserFactoryTest < Test::Unit::TestCase
:modifier => nil, :modifier => nil,
:orientation => '' :orientation => ''
).returns(:correct) ).returns(:correct)
factory = Paperclip::GeometryParserFactory.new("434x73,") factory = Paperclip::GeometryParser.new("434x73,")
output = factory.make output = factory.make
...@@ -36,7 +36,7 @@ class GeometryParserFactoryTest < Test::Unit::TestCase ...@@ -36,7 +36,7 @@ class GeometryParserFactoryTest < Test::Unit::TestCase
:modifier => nil, :modifier => nil,
:orientation => '6' :orientation => '6'
).returns(:correct) ).returns(:correct)
factory = Paperclip::GeometryParserFactory.new("300x200,6") factory = Paperclip::GeometryParser.new("300x200,6")
output = factory.make output = factory.make
...@@ -50,7 +50,7 @@ class GeometryParserFactoryTest < Test::Unit::TestCase ...@@ -50,7 +50,7 @@ class GeometryParserFactoryTest < Test::Unit::TestCase
:modifier => '#', :modifier => '#',
:orientation => nil :orientation => nil
).returns(:correct) ).returns(:correct)
factory = Paperclip::GeometryParserFactory.new("64x64#") factory = Paperclip::GeometryParser.new("64x64#")
output = factory.make output = factory.make
...@@ -64,7 +64,7 @@ class GeometryParserFactoryTest < Test::Unit::TestCase ...@@ -64,7 +64,7 @@ class GeometryParserFactoryTest < Test::Unit::TestCase
:modifier => '>', :modifier => '>',
:orientation => '7' :orientation => '7'
).returns(:correct) ).returns(:correct)
factory = Paperclip::GeometryParserFactory.new("100x50,7>") factory = Paperclip::GeometryParser.new("100x50,7>")
output = factory.make output = factory.make
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment