pixel 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README +0 -0
- data/Rakefile +33 -0
- data/VERSION +1 -0
- data/lib/pixel.rb +2 -0
- data/lib/pixel/extensions.rb +6 -0
- data/lib/pixel/pixel.rb +27 -0
- data/pixel.gemspec +52 -0
- data/spec/integer_spec.rb +17 -0
- data/spec/pixel_spec.rb +43 -0
- metadata +89 -0
data/README
ADDED
File without changes
|
data/Rakefile
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
begin
|
3
|
+
require 'jeweler'
|
4
|
+
rescue LoadError
|
5
|
+
puts "Jeweler not available. Install it with: sudo gem install jeweler"
|
6
|
+
exit 1
|
7
|
+
end
|
8
|
+
|
9
|
+
Jeweler::Tasks.new do |s|
|
10
|
+
s.name = "pixel"
|
11
|
+
s.summary = "Ruby extension for calculating the new dimensions of a resized image"
|
12
|
+
s.email = "nathaniel@pointeractive.com"
|
13
|
+
s.homepage = "http://github.com/nthj/pixel"
|
14
|
+
s.description = "Quickly calculate the new dimensions of a resized image by giving it the original dimensions, and how many pixels wide or tall you need your new image to be"
|
15
|
+
s.authors = ["Nathaniel Jones"]
|
16
|
+
|
17
|
+
s.has_rdoc = false
|
18
|
+
s.test_files = Dir['spec/*_spec.rb']
|
19
|
+
|
20
|
+
s.add_development_dependency "rspec"
|
21
|
+
end
|
22
|
+
|
23
|
+
require 'spec/rake/spectask'
|
24
|
+
|
25
|
+
desc 'Run the specs'
|
26
|
+
Spec::Rake::SpecTask.new(:spec) do |t|
|
27
|
+
t.libs << 'lib'
|
28
|
+
t.pattern = 'spec/*_spec.rb'
|
29
|
+
t.verbose = true
|
30
|
+
end
|
31
|
+
task :spec => :check_dependencies
|
32
|
+
|
33
|
+
task :default => :specs
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.2.0
|
data/lib/pixel.rb
ADDED
data/lib/pixel/pixel.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
class Pixel
|
2
|
+
def calculate dimensions = nil
|
3
|
+
[
|
4
|
+
@high || ( @wide.to_f / ratio(dimensions) ).to_i,
|
5
|
+
@wide || ( @high.to_f * ratio(dimensions) ).to_i
|
6
|
+
]
|
7
|
+
end
|
8
|
+
|
9
|
+
def high
|
10
|
+
@wide = nil
|
11
|
+
freeze
|
12
|
+
end
|
13
|
+
|
14
|
+
def initialize number
|
15
|
+
@high = @wide = number
|
16
|
+
end
|
17
|
+
|
18
|
+
def wide
|
19
|
+
@high = nil
|
20
|
+
freeze
|
21
|
+
end
|
22
|
+
|
23
|
+
protected
|
24
|
+
def ratio dimensions
|
25
|
+
dimensions.to_a.last.to_f / dimensions.to_a.first.to_f
|
26
|
+
end
|
27
|
+
end
|
data/pixel.gemspec
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{pixel}
|
8
|
+
s.version = "0.2.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Nathaniel Jones"]
|
12
|
+
s.date = %q{2010-06-24}
|
13
|
+
s.description = %q{Quickly calculate the new dimensions of a resized image by giving it the original dimensions, and how many pixels wide or tall you need your new image to be}
|
14
|
+
s.email = %q{nathaniel@pointeractive.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"README"
|
17
|
+
]
|
18
|
+
s.files = [
|
19
|
+
"README",
|
20
|
+
"Rakefile",
|
21
|
+
"VERSION",
|
22
|
+
"lib/pixel.rb",
|
23
|
+
"lib/pixel/extensions.rb",
|
24
|
+
"lib/pixel/pixel.rb",
|
25
|
+
"pixel.gemspec",
|
26
|
+
"spec/integer_spec.rb",
|
27
|
+
"spec/pixel_spec.rb"
|
28
|
+
]
|
29
|
+
s.homepage = %q{http://github.com/nthj/pixel}
|
30
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
31
|
+
s.require_paths = ["lib"]
|
32
|
+
s.rubygems_version = %q{1.3.6}
|
33
|
+
s.summary = %q{Ruby extension for calculating the new dimensions of a resized image}
|
34
|
+
s.test_files = [
|
35
|
+
"spec/integer_spec.rb",
|
36
|
+
"spec/pixel_spec.rb"
|
37
|
+
]
|
38
|
+
|
39
|
+
if s.respond_to? :specification_version then
|
40
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
41
|
+
s.specification_version = 3
|
42
|
+
|
43
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
44
|
+
s.add_development_dependency(%q<rspec>, [">= 0"])
|
45
|
+
else
|
46
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
47
|
+
end
|
48
|
+
else
|
49
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'pixel'
|
3
|
+
gem 'rspec'
|
4
|
+
|
5
|
+
describe Integer do
|
6
|
+
it "should have a pixels method" do
|
7
|
+
3.should respond_to(:pixels)
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should have a pixel method" do
|
11
|
+
1.should respond_to(:pixel)
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should return a pixel object" do
|
15
|
+
3.pixels.should be_a Pixel
|
16
|
+
end
|
17
|
+
end
|
data/spec/pixel_spec.rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'pixel'
|
3
|
+
gem 'rspec'
|
4
|
+
|
5
|
+
describe Pixel do
|
6
|
+
it "should have a calculate method" do
|
7
|
+
Pixel.new(1).should respond_to(:calculate)
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should return the specified pixels as a dimensions array" do
|
11
|
+
Pixel.new(50).calculate.should eql [50, 50]
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should attempt to turn the original dimensions into an array" do
|
15
|
+
dimensions = mock('Array', :first => 50, :last => 50, :to_a => mock('Array', :first => 50, :last => 50))
|
16
|
+
dimensions.should_receive(:to_a).at_least :once
|
17
|
+
Pixel.new(50).high.calculate dimensions
|
18
|
+
end
|
19
|
+
|
20
|
+
context "height" do
|
21
|
+
it "should calculate the new width" do
|
22
|
+
{ [100, 200] => [50, 100], [82, 620] => [50, 378], [729, 65] => [50, 4] }.each do |original, calculated|
|
23
|
+
Pixel.new(50).high.calculate(original).should eql calculated
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should freeze the object" do
|
28
|
+
lambda { Pixel.new(50).high.high }.should raise_error(TypeError)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
context "width" do
|
33
|
+
it "should calculate the new height" do
|
34
|
+
{ [100, 200] => [25, 50], [82, 100] => [41, 50], [729, 65] => [560, 50] }.each do |original, calculated|
|
35
|
+
Pixel.new(50).wide.calculate(original).should eql calculated
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should freeze the object" do
|
40
|
+
lambda { Pixel.new(50).wide.wide }.should raise_error(TypeError)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
metadata
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pixel
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 23
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 2
|
9
|
+
- 0
|
10
|
+
version: 0.2.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Nathaniel Jones
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-06-24 00:00:00 -05:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: rspec
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
version: "0"
|
33
|
+
type: :development
|
34
|
+
version_requirements: *id001
|
35
|
+
description: Quickly calculate the new dimensions of a resized image by giving it the original dimensions, and how many pixels wide or tall you need your new image to be
|
36
|
+
email: nathaniel@pointeractive.com
|
37
|
+
executables: []
|
38
|
+
|
39
|
+
extensions: []
|
40
|
+
|
41
|
+
extra_rdoc_files:
|
42
|
+
- README
|
43
|
+
files:
|
44
|
+
- README
|
45
|
+
- Rakefile
|
46
|
+
- VERSION
|
47
|
+
- lib/pixel.rb
|
48
|
+
- lib/pixel/extensions.rb
|
49
|
+
- lib/pixel/pixel.rb
|
50
|
+
- pixel.gemspec
|
51
|
+
- spec/integer_spec.rb
|
52
|
+
- spec/pixel_spec.rb
|
53
|
+
has_rdoc: true
|
54
|
+
homepage: http://github.com/nthj/pixel
|
55
|
+
licenses: []
|
56
|
+
|
57
|
+
post_install_message:
|
58
|
+
rdoc_options:
|
59
|
+
- --charset=UTF-8
|
60
|
+
require_paths:
|
61
|
+
- lib
|
62
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
63
|
+
none: false
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
hash: 3
|
68
|
+
segments:
|
69
|
+
- 0
|
70
|
+
version: "0"
|
71
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
hash: 3
|
77
|
+
segments:
|
78
|
+
- 0
|
79
|
+
version: "0"
|
80
|
+
requirements: []
|
81
|
+
|
82
|
+
rubyforge_project:
|
83
|
+
rubygems_version: 1.3.7
|
84
|
+
signing_key:
|
85
|
+
specification_version: 3
|
86
|
+
summary: Ruby extension for calculating the new dimensions of a resized image
|
87
|
+
test_files:
|
88
|
+
- spec/integer_spec.rb
|
89
|
+
- spec/pixel_spec.rb
|