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 CHANGED
@@ -2,3 +2,6 @@
2
2
  .bundle
3
3
  Gemfile.lock
4
4
  pkg/*
5
+ doc/*
6
+ .yardoc
7
+ .DS_STORE
data/lib/capit.rb CHANGED
@@ -1,5 +1,11 @@
1
- require 'capit/version'
2
- require 'capit/capture'
1
+ # encoding: UTF-8
2
+
3
+ # To ensure clean URI's
4
+ require 'postrank-uri'
3
5
 
6
+ # Primary namespace of the capit gem
4
7
  module CapIt
5
8
  end
9
+
10
+ require 'capit/version'
11
+ require 'capit/capture'
data/lib/capit/capture.rb CHANGED
@@ -1,16 +1,33 @@
1
- require 'postrank-uri'
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
- FileTest.exists?("#{@folder}/#{@filename}")
50
+ successful?
26
51
  end
27
52
 
28
- protected
29
- def determine_os
30
- case RUBY_PLATFORM
31
- when /darwin/ then :mac
32
- when /linux/ then :linux
33
- else :error
34
- end
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
@@ -1,3 +1,9 @@
1
+ # encoding: UTF-8
2
+
1
3
  module CapIt
2
- VERSION = "0.1.1"
4
+
5
+ #
6
+ # The version number
7
+ #
8
+ VERSION = "0.1.2"
3
9
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: capit
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.1
5
+ version: 0.1.2
6
6
  platform: ruby
7
7
  authors:
8
8
  - Ezekiel Templin