Class: Yabbie::Slimer
- Inherits:
-
Object
- Object
- Yabbie::Slimer
- Defined in:
- lib/yabbie/slimer.rb
Instance Attribute Summary collapse
-
#configuration ⇒ Object
Returns the value of attribute configuration.
-
#error ⇒ Object
readonly
Returns the value of attribute error.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#result ⇒ Object
readonly
Returns the value of attribute result.
-
#source ⇒ Object
Returns the value of attribute source.
Instance Method Summary collapse
- #cmd ⇒ Object
-
#initialize(url_or_file, opts = {}) ⇒ Slimer
constructor
A new instance of Slimer.
- #render(path = nil) ⇒ Object
- #run ⇒ Object
- #to_file(path = nil) ⇒ Object
- #to_string(path = nil) ⇒ Object
Constructor Details
#initialize(url_or_file, opts = {}) ⇒ Slimer
Returns a new instance of Slimer.
9 10 11 12 13 14 |
# File 'lib/yabbie/slimer.rb', line 9 def initialize(url_or_file, opts = {}) @source = Source.new(url_or_file) @options = Yabbie.configuration..merge(opts) raise NoExecutableError.new([:slimerjs]) unless command?([:slimerjs]) end |
Instance Attribute Details
#configuration ⇒ Object
Returns the value of attribute configuration.
6 7 8 |
# File 'lib/yabbie/slimer.rb', line 6 def configuration @configuration end |
#error ⇒ Object (readonly)
Returns the value of attribute error.
7 8 9 |
# File 'lib/yabbie/slimer.rb', line 7 def error @error end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
7 8 9 |
# File 'lib/yabbie/slimer.rb', line 7 def @options end |
#result ⇒ Object (readonly)
Returns the value of attribute result.
7 8 9 |
# File 'lib/yabbie/slimer.rb', line 7 def result @result end |
#source ⇒ Object
Returns the value of attribute source.
6 7 8 |
# File 'lib/yabbie/slimer.rb', line 6 def source @source end |
Instance Method Details
#cmd ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/yabbie/slimer.rb', line 28 def cmd [ prepend_command, slimerjs, command_config_file, command_error_log, script, @source.to_s.shellescape, outfile, width, height, format, timeout ].join(" ").strip end |
#render(path = nil) ⇒ Object
44 45 46 47 48 49 50 51 |
# File 'lib/yabbie/slimer.rb', line 44 def render(path = nil) @outfile = File.(path) if path self.run raise Yabbie::RenderingError.new(@error) if @error @outfile end |
#run ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/yabbie/slimer.rb', line 16 def run @error = nil @result = `#{cmd}` unless $?.exitstatus == 0 @error = @result @result = nil end @result end |
#to_file(path = nil) ⇒ Object
53 54 55 56 |
# File 'lib/yabbie/slimer.rb', line 53 def to_file(path = nil) self.render(path) File.new(@outfile) end |
#to_string(path = nil) ⇒ Object
58 59 60 |
# File 'lib/yabbie/slimer.rb', line 58 def to_string(path = nil) File.open(self.render(path)).read end |