Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
paperclip
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ikcrm_common
paperclip
Commits
233fcb90
Commit
233fcb90
authored
Nov 16, 2012
by
Jon Yurek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Don't use Factory in the name. It's tacky.
parent
8338024a
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
17 additions
and
17 deletions
+17
-17
lib/paperclip/geometry.rb
+3
-3
lib/paperclip/geometry_detector_factory.rb
+2
-2
lib/paperclip/geometry_parser_factory.rb
+1
-1
test/geometry_detector_factory_test.rb
+5
-5
test/geometry_parser_factory_test.rb
+6
-6
No files found.
lib/paperclip/geometry.rb
View file @
233fcb90
...
@@ -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
)
GeometryDetector
Factory
.
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
)
GeometryParser
Factory
.
new
(
string
).
make
GeometryParser
.
new
(
string
).
make
end
end
# Swaps the height and width if necessary
# Swaps the height and width if necessary
...
...
lib/paperclip/geometry_detector_factory.rb
View file @
233fcb90
module
Paperclip
module
Paperclip
class
GeometryDetector
Factory
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
GeometryParser
Factory
.
new
(
geometry_string
.
strip
).
make
||
GeometryParser
.
new
(
geometry_string
.
strip
).
make
||
raise
(
Errors
::
NotIdentifiedByImageMagickError
.
new
)
raise
(
Errors
::
NotIdentifiedByImageMagickError
.
new
)
end
end
...
...
lib/paperclip/geometry_parser_factory.rb
View file @
233fcb90
module
Paperclip
module
Paperclip
class
GeometryParser
Factory
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
...
...
test/geometry_detector_factory_test.rb
View file @
233fcb90
require
'./test/helper'
require
'./test/helper'
class
GeometryDetector
Factory
Test
<
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
::
GeometryParser
Factory
.
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
::
GeometryDetector
Factory
.
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
::
GeometryParser
Factory
.
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
::
GeometryDetector
Factory
.
new
(
file
)
factory
=
Paperclip
::
GeometryDetector
.
new
(
file
)
output
=
factory
.
make
output
=
factory
.
make
...
...
test/geometry_parser_factory_test.rb
View file @
233fcb90
require
'./test/helper'
require
'./test/helper'
class
GeometryParser
Factory
Test
<
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
::
GeometryParser
Factory
.
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
::
GeometryParser
Factory
.
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
::
GeometryParser
Factory
.
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
::
GeometryParser
Factory
.
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
::
GeometryParser
Factory
.
new
(
"100x50,7>"
)
factory
=
Paperclip
::
GeometryParser
.
new
(
"100x50,7>"
)
output
=
factory
.
make
output
=
factory
.
make
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment