capit 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +3 -0
- data/lib/capit.rb +8 -2
- data/lib/capit/capture.rb +61 -11
- data/lib/capit/version.rb +7 -1
- metadata +1 -1
data/.gitignore
CHANGED
data/lib/capit.rb
CHANGED
data/lib/capit/capture.rb
CHANGED
@@ -1,16 +1,33 @@
|
|
1
|
-
|
1
|
+
# encoding: UTF-8
|
2
2
|
|
3
3
|
module CapIt
|
4
4
|
class << self
|
5
|
+
|
6
|
+
# Capture image from URL. Convenience method for {CapIt::Capture}
|
7
|
+
#
|
8
|
+
# @example
|
9
|
+
# CapIt::Capture("http://mdvlrb.com", :filename => "mdvlrb.jpg")
|
10
|
+
#
|
5
11
|
def Capture url, options = {}
|
6
12
|
CapIt::Capture.new(url, options).capture
|
7
13
|
end
|
8
14
|
end
|
9
15
|
|
10
16
|
class Capture
|
17
|
+
# The URL of the page to be captured
|
11
18
|
attr_reader :url
|
12
|
-
attr_accessor :folder, :filename, :user_agent, :max_wait, :delay
|
13
19
|
|
20
|
+
|
21
|
+
attr_accessor :folder, :filename, :user_agent, :max_wait,
|
22
|
+
:delay, :output
|
23
|
+
|
24
|
+
# Initialize a new Capture
|
25
|
+
#
|
26
|
+
# @example
|
27
|
+
# capit = CapIt::Capture.new("http://mdvlrb.com", :filename => "mdvlrb.png")
|
28
|
+
# capit.max_wait = 5000
|
29
|
+
# capit.folder = "/home/user/screenshots"
|
30
|
+
#
|
14
31
|
def initialize url, options = {}
|
15
32
|
@url = PostRank::URI.clean(url)
|
16
33
|
@folder = options[:folder] || Dir.pwd
|
@@ -19,21 +36,41 @@ module CapIt
|
|
19
36
|
@max_wait = options[:max_wait] || 15000
|
20
37
|
@delay = options[:delay]
|
21
38
|
end
|
22
|
-
|
39
|
+
|
40
|
+
# Performs the page capture.
|
41
|
+
#
|
42
|
+
# @example
|
43
|
+
# capit = CapIt::Capture.new("http://mdvlrb.com", :filename => "mdvlrb.png", :folder => "/home/user/screenshots")
|
44
|
+
# capit.capture
|
45
|
+
#
|
46
|
+
# @return [true, false]
|
47
|
+
#
|
23
48
|
def capture
|
24
49
|
`#{capture_command}`
|
25
|
-
|
50
|
+
successful?
|
26
51
|
end
|
27
52
|
|
28
|
-
protected
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
53
|
+
protected
|
54
|
+
|
55
|
+
# Determines whether the capture was successful
|
56
|
+
# by checking for the existence of the output file.
|
57
|
+
# Sets {@output} if true.
|
58
|
+
#
|
59
|
+
# @return [true, false]
|
60
|
+
#
|
61
|
+
def successful?
|
62
|
+
if FileTest.exists?("#{@folder}/#{@filename}")
|
63
|
+
@output = "#{@folder}/#{@filename}"
|
64
|
+
true
|
65
|
+
else
|
66
|
+
false
|
67
|
+
end
|
35
68
|
end
|
36
69
|
|
70
|
+
# Produces the command used to run CutyCapt.
|
71
|
+
#
|
72
|
+
# @return [String]
|
73
|
+
#
|
37
74
|
def capture_command
|
38
75
|
cmd = "CutyCapt"
|
39
76
|
cmd += " --url='#{@url}'"
|
@@ -49,5 +86,18 @@ module CapIt
|
|
49
86
|
cmd
|
50
87
|
end
|
51
88
|
end
|
89
|
+
|
90
|
+
# Uses RUBY_PLATFORM to determine the operating system.
|
91
|
+
# Not foolproof, but good enough for the time being.
|
92
|
+
#
|
93
|
+
# @return [Symbol]
|
94
|
+
#
|
95
|
+
def determine_os
|
96
|
+
case RUBY_PLATFORM
|
97
|
+
when /darwin/ then :mac
|
98
|
+
when /linux/ then :linux
|
99
|
+
else :error
|
100
|
+
end
|
101
|
+
end
|
52
102
|
end
|
53
103
|
end
|
data/lib/capit/version.rb
CHANGED