Commit 233fcb90 by Jon Yurek

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

parent 8338024a
......@@ -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]
......@@ -23,14 +23,14 @@ module Paperclip
# 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
......
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
......
module Paperclip
class GeometryParserFactory
class GeometryParser
FORMAT = /\b(\d*)x?(\d*)\b(?:,(\d?))?([\>\<\#\@\%^!])?/i
def initialize(string)
@string = string
......
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
......@@ -12,9 +12,9 @@ class GeometryDetectorFactoryTest < Test::Unit::TestCase
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
......
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',
......@@ -8,7 +8,7 @@ class GeometryParserFactoryTest < Test::Unit::TestCase
:modifier => nil,
:orientation => nil
).returns(:correct)
factory = Paperclip::GeometryParserFactory.new("434x73")
factory = Paperclip::GeometryParser.new("434x73")
output = factory.make
......@@ -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
......@@ -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
......@@ -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
......@@ -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
......
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