spider_monkey 0.0.3 → 0.0.4
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.
- checksums.yaml +4 -4
- data/Rakefile +8 -0
- data/lib/spider_monkey.rb +2 -0
- data/lib/spider_monkey/config.rb +1 -0
- data/lib/spider_monkey/helper.rb +11 -4
- data/lib/spider_monkey/validator.rb +288 -0
- data/spider_monkey.gemspec +5 -2
- data/test/test_helper.rb +2 -0
- data/test/test_validator.rb +256 -0
- metadata +34 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ca54d3b1d9e3ae2d36c0baff41cec4bf784e8d76
|
4
|
+
data.tar.gz: 6e72c92b2332feadc22301c34d8979085ecab0d2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 39f64bccf3aa5bb8e57f471a9dc4a2558b5dfeb17ed2b3fe4a75422060f069c0a62e9e8ec2e1d708b8db01a7840283947c1c5745581f0870cc2db425bf6579c6
|
7
|
+
data.tar.gz: 28ba8f0600e665273eada889d9e6b509c809e77ae50cdbb782703ba81094e0ab1fef9b847404df3cc6bdd7b75eb5dcea6feecf5e760e73da000bfed1a83926e6
|
data/Rakefile
ADDED
data/lib/spider_monkey.rb
CHANGED
data/lib/spider_monkey/config.rb
CHANGED
data/lib/spider_monkey/helper.rb
CHANGED
@@ -4,12 +4,19 @@ module SpiderMonkey
|
|
4
4
|
options = options.reverse_merge(
|
5
5
|
key: SpiderMonkey.configuration[:user_key]
|
6
6
|
)
|
7
|
-
|
8
|
-
|
7
|
+
validation = SpiderMonkey::Validator.new(options).validate_options
|
8
|
+
if validation[:passed] || validation[:recoverable]
|
9
|
+
options = validation[:valid_options]
|
10
|
+
|
11
|
+
options_string = spider_monkey_string_from_options_hash(options)
|
12
|
+
signature = spider_monkey_signature_from_options_string(options_string)
|
9
13
|
|
10
|
-
|
14
|
+
compressed_string = Base64.urlsafe_encode64(Zlib::Deflate.deflate(options_string))
|
11
15
|
|
12
|
-
|
16
|
+
"#{SpiderMonkey.configuration[:protocol]}://#{SpiderMonkey.configuration[:cloudfront_host]}/c?o=#{compressed_string}&s=#{signature}"
|
17
|
+
else
|
18
|
+
""
|
19
|
+
end
|
13
20
|
end
|
14
21
|
|
15
22
|
private
|
@@ -0,0 +1,288 @@
|
|
1
|
+
module SpiderMonkey
|
2
|
+
class Validator
|
3
|
+
def initialize(options = {})
|
4
|
+
@options = options
|
5
|
+
end
|
6
|
+
|
7
|
+
def validate_options
|
8
|
+
@passed = true
|
9
|
+
@recoverable = true
|
10
|
+
@valid_options = {}
|
11
|
+
@invalid_options = {}
|
12
|
+
@messages = []
|
13
|
+
|
14
|
+
@options.each do |key, value|
|
15
|
+
# First, lets loop through them all and remove any invalid keys
|
16
|
+
if !is_allowed_root_key?(key)
|
17
|
+
@invalid_options[key] = value
|
18
|
+
@options.delete(key)
|
19
|
+
@messages << "Extra Key present: #{key}"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
if is_source?(@options, "source")
|
25
|
+
@valid_options[:source_url] = @options[:source_url] if @options[:source_url]
|
26
|
+
@valid_options[:source_key] = @options[:source_key] if @options[:source_key]
|
27
|
+
@valid_options[:source_bucket] = @options[:source_bucket] if @options[:source_bucket]
|
28
|
+
else
|
29
|
+
@messages << "Invalid Source."
|
30
|
+
@recoverable = false
|
31
|
+
@invalid_options[:source_url] = @options[:source_url] if @options[:source_url]
|
32
|
+
@invalid_options[:source_key] = @options[:source_key] if @options[:source_key]
|
33
|
+
@invalid_options[:source_bucket] = @options[:source_bucket] if @options[:source_bucket]
|
34
|
+
end
|
35
|
+
|
36
|
+
@options.delete(:source_url)
|
37
|
+
@options.delete(:source_key)
|
38
|
+
@options.delete(:source_bucket)
|
39
|
+
|
40
|
+
|
41
|
+
validate_option(:colorspace, :read_colorspace)
|
42
|
+
validate_option(:integer_like, :read_density)
|
43
|
+
validate_option(:integer_like, :quality)
|
44
|
+
validate_option(:integer_like, :width, true)
|
45
|
+
validate_option(:integer_like, :height, true)
|
46
|
+
validate_option(:resize_method, :resize_method)
|
47
|
+
validate_option(:gravity, :resize_gravity)
|
48
|
+
validate_option(:boolean, :thumbnail)
|
49
|
+
validate_option(:integer_like, :density)
|
50
|
+
validate_option(:string, :key, true)
|
51
|
+
validate_option(:colorspace, :colorspace)
|
52
|
+
validate_option(:color, :background_color)
|
53
|
+
|
54
|
+
#:annotate,
|
55
|
+
@valid_options[:annotate] = @options[:annotate] if @options[:annotate]
|
56
|
+
#:composite
|
57
|
+
@valid_options[:composite] = @options[:composite] if @options[:composite]
|
58
|
+
|
59
|
+
#:annotate
|
60
|
+
# array, or single element
|
61
|
+
# :gravity
|
62
|
+
# :weight integer
|
63
|
+
# :pointsize interger
|
64
|
+
# :color "blue", "#123456", "rgb(1,1,1)", "rgba(12,12,12)"
|
65
|
+
# :translate_x integer
|
66
|
+
# :translate_y integer
|
67
|
+
# :text (required) string
|
68
|
+
|
69
|
+
# :composite
|
70
|
+
# :url / :key && :bucket
|
71
|
+
# width numeric or percentage
|
72
|
+
# height
|
73
|
+
# :resize_gravity
|
74
|
+
# :disolve_percent optional - integer 0-100
|
75
|
+
|
76
|
+
|
77
|
+
if @messages.size > 0
|
78
|
+
@passed = false
|
79
|
+
end
|
80
|
+
|
81
|
+
SpiderMonkey.configuration[:validation_error_handler].call(@messages, @recoverable, @valid_options, @invalid_options) unless @passed
|
82
|
+
return {
|
83
|
+
passed: @passed,
|
84
|
+
recoverable: @recoverable,
|
85
|
+
valid_options: @valid_options
|
86
|
+
}
|
87
|
+
end
|
88
|
+
|
89
|
+
def validate_option(validation_type, key, required = false)
|
90
|
+
if @options[key].present?
|
91
|
+
if send("is_#{validation_type}?".to_sym, @options[key])
|
92
|
+
@valid_options[key] = @options[key]
|
93
|
+
else
|
94
|
+
@recoverable = false
|
95
|
+
@messages << "Invalid parameter: #{key}."
|
96
|
+
@invalid_options[key] = @options[key]
|
97
|
+
end
|
98
|
+
elsif required
|
99
|
+
@recoverable = false
|
100
|
+
@messages << "Missing parameter: #{key}"
|
101
|
+
end
|
102
|
+
@options.delete(key)
|
103
|
+
end
|
104
|
+
|
105
|
+
|
106
|
+
def is_integer_like?(input)
|
107
|
+
is_integer?(input) || /\A[-+]?\d+\z/ === input
|
108
|
+
end
|
109
|
+
|
110
|
+
def is_integer?(input)
|
111
|
+
input.kind_of? Integer
|
112
|
+
end
|
113
|
+
|
114
|
+
def is_string?(input)
|
115
|
+
input.kind_of?(String) && !input.blank?
|
116
|
+
end
|
117
|
+
|
118
|
+
def is_symbol?(input)
|
119
|
+
input.kind_of? Symbol
|
120
|
+
end
|
121
|
+
|
122
|
+
def is_boolean?(input)
|
123
|
+
input.kind_of?(TrueClass) || input.kind_of?(FalseClass)
|
124
|
+
end
|
125
|
+
|
126
|
+
def is_color?(input)
|
127
|
+
# This is really just a semi-validator.
|
128
|
+
return false unless is_string?(input) || is_symbol?(input)
|
129
|
+
|
130
|
+
input = input.to_s
|
131
|
+
|
132
|
+
if input.starts_with?("#")
|
133
|
+
# We have a hash color
|
134
|
+
# All Valid:
|
135
|
+
# #00F
|
136
|
+
# #0000FF
|
137
|
+
# #0000FFFF (w/ alpha)
|
138
|
+
return false unless [4, 7, 9].include?(input.length)
|
139
|
+
hex_input = input[1..(input.length)] # everything except the first character
|
140
|
+
return !hex_input[/\H/]
|
141
|
+
elsif input.starts_with?("rgba")
|
142
|
+
# 1 of each parentheses and 3 commas
|
143
|
+
return input.scan("(").count == 1 && input.scan(")").count == 1 && input.scan(",").count == 3
|
144
|
+
elsif input.starts_with?("rgb")
|
145
|
+
# 1 of each parentheses and 2 commas
|
146
|
+
return input.scan("(").count == 1 && input.scan(")").count == 1 && input.scan(",").count == 2
|
147
|
+
else
|
148
|
+
# Some other string. We're going to just assume it's a color. In an
|
149
|
+
# ideal world we would check it against the valid list, but that's way
|
150
|
+
# too detailed.
|
151
|
+
return true
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
def is_gravity?(input)
|
156
|
+
%w(
|
157
|
+
northwest
|
158
|
+
north
|
159
|
+
northeast
|
160
|
+
west
|
161
|
+
center
|
162
|
+
east
|
163
|
+
southwest
|
164
|
+
south
|
165
|
+
southeast
|
166
|
+
).include?(input.to_s.downcase)
|
167
|
+
end
|
168
|
+
|
169
|
+
def is_colorspace?(input)
|
170
|
+
%w(
|
171
|
+
CIELab
|
172
|
+
CMY
|
173
|
+
CMYK
|
174
|
+
Gray
|
175
|
+
HCL
|
176
|
+
HCLp
|
177
|
+
HSB
|
178
|
+
HSI
|
179
|
+
HSL
|
180
|
+
HSV
|
181
|
+
HWB
|
182
|
+
Lab
|
183
|
+
LCH
|
184
|
+
LCHab
|
185
|
+
LCHuv
|
186
|
+
LMS
|
187
|
+
Log
|
188
|
+
Luv
|
189
|
+
OHTA
|
190
|
+
Rec601Luma
|
191
|
+
Rec601YCbCr
|
192
|
+
Rec709Luma
|
193
|
+
Rec709YCbCr
|
194
|
+
RGB
|
195
|
+
scRGB
|
196
|
+
sRGB
|
197
|
+
Transparent
|
198
|
+
XYZ
|
199
|
+
xyY
|
200
|
+
YCbCr
|
201
|
+
YDbDr
|
202
|
+
YCC
|
203
|
+
YIQ
|
204
|
+
YPbPr
|
205
|
+
YUV
|
206
|
+
).include?(input.to_s)
|
207
|
+
end
|
208
|
+
|
209
|
+
def is_percent?(input)
|
210
|
+
# String, with a percent sign, and an integer
|
211
|
+
input.kind_of?(String) && input.include?('%') && is_integer_like?(input.gsub('%', ''))
|
212
|
+
end
|
213
|
+
|
214
|
+
def is_url?(input)
|
215
|
+
# Super lame test
|
216
|
+
is_string?(input) && ( input.starts_with?("http://") || input.starts_with?("https://") ) && input.length > 10
|
217
|
+
end
|
218
|
+
|
219
|
+
def is_resize_method?(input)
|
220
|
+
return false unless is_string?(input) || is_symbol?(input)
|
221
|
+
["crop", "fit"].include? input.to_s.downcase
|
222
|
+
end
|
223
|
+
|
224
|
+
def is_source?(input, prefix = nil)
|
225
|
+
return false unless input.kind_of? Hash
|
226
|
+
|
227
|
+
if prefix.present?
|
228
|
+
prefix = prefix + "_"
|
229
|
+
end
|
230
|
+
|
231
|
+
if input.has_key?("#{prefix}url".to_sym)
|
232
|
+
return false unless !input.has_key?("#{prefix}bucket".to_sym) && !input.has_key?("#{prefix}key".to_sym)
|
233
|
+
return is_url?(input["#{prefix}url".to_sym])
|
234
|
+
elsif (input.has_key?("#{prefix}bucket".to_sym) && input.has_key?("#{prefix}key".to_sym))
|
235
|
+
return false unless !input.has_key?("#{prefix}url".to_sym)
|
236
|
+
return (is_string?(input["#{prefix}bucket".to_sym]) && is_string?(input["#{prefix}key".to_sym]))
|
237
|
+
else
|
238
|
+
return false
|
239
|
+
end
|
240
|
+
end
|
241
|
+
|
242
|
+
def is_allowed_root_key?(symbol)
|
243
|
+
[
|
244
|
+
:key,
|
245
|
+
:source_url,
|
246
|
+
:source_key,
|
247
|
+
:source_bucket,
|
248
|
+
:read_density,
|
249
|
+
:read_colorspace,
|
250
|
+
:quality,
|
251
|
+
:width,
|
252
|
+
:height,
|
253
|
+
:resize_method,
|
254
|
+
:resize_gravity,
|
255
|
+
:thumbnail,
|
256
|
+
:density,
|
257
|
+
:colorspace,
|
258
|
+
:annotate,
|
259
|
+
:composite,
|
260
|
+
:background_color
|
261
|
+
].include?(symbol)
|
262
|
+
end
|
263
|
+
|
264
|
+
def is_allowed_annotate_key?(symbol)
|
265
|
+
[
|
266
|
+
:gravity,
|
267
|
+
:weight,
|
268
|
+
:pointsize,
|
269
|
+
:color,
|
270
|
+
:translate_x,
|
271
|
+
:translate_y,
|
272
|
+
:text
|
273
|
+
].include?(symbol)
|
274
|
+
end
|
275
|
+
|
276
|
+
def is_allowed_composite_key?(symbol)
|
277
|
+
[
|
278
|
+
:url,
|
279
|
+
:key,
|
280
|
+
:bucket,
|
281
|
+
:width,
|
282
|
+
:height,
|
283
|
+
:resize_gravity,
|
284
|
+
:disolve_percent
|
285
|
+
].include?(symbol)
|
286
|
+
end
|
287
|
+
end
|
288
|
+
end
|
data/spider_monkey.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = "spider_monkey"
|
3
|
-
s.version = "0.0.
|
3
|
+
s.version = "0.0.4"
|
4
4
|
s.platform = Gem::Platform::RUBY
|
5
5
|
|
6
6
|
s.authors = ["Ben McFadden"]
|
@@ -9,10 +9,13 @@ Gem::Specification.new do |s|
|
|
9
9
|
s.email = "ben@forgeapps.com"
|
10
10
|
s.files = `git ls-files`.split("\n")
|
11
11
|
|
12
|
-
#s.homepage = "
|
12
|
+
#s.homepage = ""
|
13
13
|
s.licenses = ["MIT"]
|
14
14
|
s.require_paths = ["lib"]
|
15
15
|
s.rubygems_version = "2.0.3"
|
16
16
|
s.summary = "usespidermonkey.com integration"
|
17
|
+
|
18
|
+
s.add_dependency "activesupport"
|
19
|
+
s.add_development_dependency "minitest-reporters"
|
17
20
|
|
18
21
|
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,256 @@
|
|
1
|
+
require 'minitest/autorun'
|
2
|
+
require 'spider_monkey'
|
3
|
+
|
4
|
+
class SpiderMonkeyValidatorTest < Minitest::Test
|
5
|
+
def test_validate_options
|
6
|
+
url = "http://example.com/image.jpg"
|
7
|
+
|
8
|
+
options = {width: 150, height: 85, resize_method: :crop, resize_gravity: "Center", density: 300, quality: 90, thumbnail: true, source_url: url, key: "asdf"}
|
9
|
+
validator = SpiderMonkey::Validator.new(options)
|
10
|
+
response = validator.validate_options
|
11
|
+
assert response[:passed]
|
12
|
+
assert response[:recoverable]
|
13
|
+
|
14
|
+
options = {extra_params: "foobar", width: 150, height: 85, resize_method: :crop, resize_gravity: "Center", density: 300, quality: 90, thumbnail: true, source_url: url, key: "asdf"}
|
15
|
+
validator = SpiderMonkey::Validator.new(options)
|
16
|
+
response = validator.validate_options
|
17
|
+
refute response[:passed]
|
18
|
+
assert response[:recoverable]
|
19
|
+
|
20
|
+
|
21
|
+
options = {width: nil, height: 85, resize_method: :crop, resize_gravity: "Center", density: 300, quality: 90, thumbnail: true, source_url: url, key: "asdf"}
|
22
|
+
validator = SpiderMonkey::Validator.new(options)
|
23
|
+
response = validator.validate_options
|
24
|
+
refute response[:passed]
|
25
|
+
refute response[:recoverable]
|
26
|
+
|
27
|
+
options = {height: 85, resize_method: :crop, resize_gravity: "Center", density: 300, quality: 90, thumbnail: true, source_url: url, key: "asdf"}
|
28
|
+
validator = SpiderMonkey::Validator.new(options)
|
29
|
+
response = validator.validate_options
|
30
|
+
refute response[:passed]
|
31
|
+
refute response[:recoverable]
|
32
|
+
|
33
|
+
options = {width: "foo", height: 85, resize_method: :crop, resize_gravity: "Center", density: 300, quality: 90, thumbnail: true, source_url: url, key: "asdf"}
|
34
|
+
validator = SpiderMonkey::Validator.new(options)
|
35
|
+
response = validator.validate_options
|
36
|
+
refute response[:passed]
|
37
|
+
refute response[:recoverable]
|
38
|
+
|
39
|
+
options = {}
|
40
|
+
validator = SpiderMonkey::Validator.new(options)
|
41
|
+
response = validator.validate_options
|
42
|
+
refute response[:passed]
|
43
|
+
refute response[:recoverable]
|
44
|
+
|
45
|
+
options = {width: 150, height: 85, source_url: url, key: "asdf"}
|
46
|
+
validator = SpiderMonkey::Validator.new(options)
|
47
|
+
response = validator.validate_options
|
48
|
+
assert response[:passed]
|
49
|
+
assert response[:recoverable]
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_is_integer?
|
53
|
+
validator = SpiderMonkey::Validator.new
|
54
|
+
assert validator.is_integer?(3)
|
55
|
+
|
56
|
+
refute validator.is_integer?("300")
|
57
|
+
refute validator.is_integer?("3")
|
58
|
+
refute validator.is_integer?(3.0)
|
59
|
+
refute validator.is_integer?("3.0")
|
60
|
+
refute validator.is_integer?("3oo")
|
61
|
+
refute validator.is_integer?("")
|
62
|
+
refute validator.is_integer?(nil)
|
63
|
+
refute validator.is_integer?("thirty")
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_is_integer_like?
|
67
|
+
validator = SpiderMonkey::Validator.new
|
68
|
+
assert validator.is_integer_like?(3)
|
69
|
+
assert validator.is_integer_like?("300")
|
70
|
+
assert validator.is_integer_like?("3")
|
71
|
+
|
72
|
+
refute validator.is_integer_like?(3.0)
|
73
|
+
refute validator.is_integer_like?("3.0")
|
74
|
+
refute validator.is_integer_like?("3oo")
|
75
|
+
refute validator.is_integer_like?("")
|
76
|
+
refute validator.is_integer_like?(nil)
|
77
|
+
refute validator.is_integer_like?("thirty")
|
78
|
+
end
|
79
|
+
|
80
|
+
def test_is_string?
|
81
|
+
validator = SpiderMonkey::Validator.new
|
82
|
+
assert validator.is_string?("asdf")
|
83
|
+
assert validator.is_string?("14")
|
84
|
+
|
85
|
+
refute validator.is_string?(14)
|
86
|
+
end
|
87
|
+
|
88
|
+
def test_is_boolean?
|
89
|
+
validator = SpiderMonkey::Validator.new
|
90
|
+
assert validator.is_boolean?(true)
|
91
|
+
assert validator.is_boolean?(false)
|
92
|
+
|
93
|
+
refute validator.is_boolean?("false")
|
94
|
+
refute validator.is_boolean?("true")
|
95
|
+
refute validator.is_boolean?("asdf")
|
96
|
+
refute validator.is_boolean?(0)
|
97
|
+
refute validator.is_boolean?(1)
|
98
|
+
end
|
99
|
+
|
100
|
+
def test_is_color?
|
101
|
+
validator = SpiderMonkey::Validator.new
|
102
|
+
|
103
|
+
assert validator.is_color?("blue")
|
104
|
+
assert validator.is_color?(:blue)
|
105
|
+
assert validator.is_color?("#0000FF")
|
106
|
+
assert validator.is_color?("#0000FF00")
|
107
|
+
assert validator.is_color?("rgb(0,0,255)")
|
108
|
+
assert validator.is_color?("rgba(0,0,255, 0.5)")
|
109
|
+
|
110
|
+
refute validator.is_color?("#asdf")
|
111
|
+
refute validator.is_color?("#1234567")
|
112
|
+
refute validator.is_color?("#123456HH")
|
113
|
+
refute validator.is_color?("rgba(0,0,255)") #said rgba but didn't include alpha
|
114
|
+
refute validator.is_color?("rgb(0,0,255, 0.5)")
|
115
|
+
refute validator.is_color?("rgb(0)")
|
116
|
+
refute validator.is_color?("rgb(blue)")
|
117
|
+
end
|
118
|
+
|
119
|
+
def test_is_gravity?
|
120
|
+
validator = SpiderMonkey::Validator.new
|
121
|
+
gravities = %w(
|
122
|
+
northwest
|
123
|
+
north
|
124
|
+
northeast
|
125
|
+
west
|
126
|
+
center
|
127
|
+
east
|
128
|
+
southwest
|
129
|
+
south
|
130
|
+
southeast
|
131
|
+
)
|
132
|
+
|
133
|
+
gravities.each do |g|
|
134
|
+
assert validator.is_gravity?(g)
|
135
|
+
end
|
136
|
+
|
137
|
+
assert validator.is_gravity?(:center)
|
138
|
+
assert validator.is_gravity?("Center")
|
139
|
+
|
140
|
+
assert validator.is_gravity?("NorthWest")
|
141
|
+
assert validator.is_gravity?("Northwest")
|
142
|
+
|
143
|
+
refute validator.is_gravity?("Middle")
|
144
|
+
refute validator.is_gravity?("Purple")
|
145
|
+
refute validator.is_gravity?("foobar")
|
146
|
+
end
|
147
|
+
|
148
|
+
def test_is_colorspace?
|
149
|
+
validator = SpiderMonkey::Validator.new
|
150
|
+
colorspaces = %w(
|
151
|
+
CIELab
|
152
|
+
CMY
|
153
|
+
CMYK
|
154
|
+
Gray
|
155
|
+
HCL
|
156
|
+
HCLp
|
157
|
+
HSB
|
158
|
+
HSI
|
159
|
+
HSL
|
160
|
+
HSV
|
161
|
+
HWB
|
162
|
+
Lab
|
163
|
+
LCH
|
164
|
+
LCHab
|
165
|
+
LCHuv
|
166
|
+
LMS
|
167
|
+
Log
|
168
|
+
Luv
|
169
|
+
OHTA
|
170
|
+
Rec601Luma
|
171
|
+
Rec601YCbCr
|
172
|
+
Rec709Luma
|
173
|
+
Rec709YCbCr
|
174
|
+
RGB
|
175
|
+
scRGB
|
176
|
+
sRGB
|
177
|
+
Transparent
|
178
|
+
XYZ
|
179
|
+
xyY
|
180
|
+
YCbCr
|
181
|
+
YDbDr
|
182
|
+
YCC
|
183
|
+
YIQ
|
184
|
+
YPbPr
|
185
|
+
YUV
|
186
|
+
)
|
187
|
+
|
188
|
+
colorspaces.each do |g|
|
189
|
+
assert validator.is_colorspace?(g)
|
190
|
+
end
|
191
|
+
|
192
|
+
refute validator.is_colorspace?("srgb")
|
193
|
+
refute validator.is_colorspace?("Weee")
|
194
|
+
refute validator.is_colorspace?("")
|
195
|
+
refute validator.is_colorspace?("cmyk")
|
196
|
+
end
|
197
|
+
|
198
|
+
def test_is_percent?
|
199
|
+
validator = SpiderMonkey::Validator.new
|
200
|
+
# String, with a percent sign, and an integer
|
201
|
+
|
202
|
+
assert validator.is_percent? "4%"
|
203
|
+
assert validator.is_percent? "40%"
|
204
|
+
assert validator.is_percent? "14%"
|
205
|
+
assert validator.is_percent? "154%"
|
206
|
+
|
207
|
+
refute validator.is_percent? "154"
|
208
|
+
refute validator.is_percent? "%"
|
209
|
+
refute validator.is_percent? 14
|
210
|
+
end
|
211
|
+
|
212
|
+
def test_is_url?
|
213
|
+
validator = SpiderMonkey::Validator.new
|
214
|
+
|
215
|
+
assert validator.is_url?("http://asdf.com/asdf")
|
216
|
+
assert validator.is_url?("https://asdf.com/asdf")
|
217
|
+
|
218
|
+
refute validator.is_url?("asdf")
|
219
|
+
refute validator.is_url?("asdfasdfasdf")
|
220
|
+
refute validator.is_url?("https://")
|
221
|
+
end
|
222
|
+
|
223
|
+
def test_is_resize_method?
|
224
|
+
validator = SpiderMonkey::Validator.new
|
225
|
+
assert validator.is_resize_method? :crop
|
226
|
+
assert validator.is_resize_method? :fit
|
227
|
+
assert validator.is_resize_method? "crop"
|
228
|
+
|
229
|
+
refute validator.is_resize_method? :magic
|
230
|
+
refute validator.is_resize_method? "magic"
|
231
|
+
end
|
232
|
+
|
233
|
+
def test_is_source?
|
234
|
+
validator = SpiderMonkey::Validator.new
|
235
|
+
assert validator.is_source?({key: "foo", bucket: "bar"})
|
236
|
+
assert validator.is_source?({url: "http://fizbam.com"})
|
237
|
+
|
238
|
+
assert validator.is_source?({source_key: "foo", source_bucket: "bar"}, "source")
|
239
|
+
assert validator.is_source?({source_url: "http://fizbam.com"}, "source")
|
240
|
+
|
241
|
+
refute validator.is_source?({key: "foo", bucket: "bar"}, "source")
|
242
|
+
refute validator.is_source?({url: "http://fizbam.com"}, "source")
|
243
|
+
|
244
|
+
|
245
|
+
refute validator.is_source?({url: "fizbam"})
|
246
|
+
refute validator.is_source?({url: "fizbam", key: "asdf"})
|
247
|
+
refute validator.is_source?({url: "fizbam", bucket: "fsda"})
|
248
|
+
refute validator.is_source?({key: "fizbam", bucket: ""})
|
249
|
+
refute validator.is_source?({key: "", bucket: "fsda"})
|
250
|
+
refute validator.is_source?({key: "asdf"})
|
251
|
+
refute validator.is_source?({bucket: "asdf"})
|
252
|
+
refute validator.is_source?({key: "asdf", bucket: nil})
|
253
|
+
refute validator.is_source?({key: nil, bucket: "asdf"})
|
254
|
+
refute validator.is_source?({})
|
255
|
+
end
|
256
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: spider_monkey
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ben McFadden
|
@@ -9,17 +9,49 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
date: 2015-11-19 00:00:00.000000000 Z
|
12
|
-
dependencies:
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activesupport
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: minitest-reporters
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
13
41
|
description: A gem to simplify generating image URLs for usespidermonkey.com
|
14
42
|
email: ben@forgeapps.com
|
15
43
|
executables: []
|
16
44
|
extensions: []
|
17
45
|
extra_rdoc_files: []
|
18
46
|
files:
|
47
|
+
- Rakefile
|
19
48
|
- lib/spider_monkey.rb
|
20
49
|
- lib/spider_monkey/config.rb
|
21
50
|
- lib/spider_monkey/helper.rb
|
51
|
+
- lib/spider_monkey/validator.rb
|
22
52
|
- spider_monkey.gemspec
|
53
|
+
- test/test_helper.rb
|
54
|
+
- test/test_validator.rb
|
23
55
|
homepage:
|
24
56
|
licenses:
|
25
57
|
- MIT
|