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, options = {}) ⇒ 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, options = {}) ⇒ Slimer
Returns a new instance of Slimer.
8 9 10 11 12 13 |
# File 'lib/yabbie/slimer.rb', line 8 def initialize(url_or_file, = {}) @source = Source.new(url_or_file) @options = Yabbie.configuration..merge() raise NoExecutableError.new unless File.exists?(Yabbie.configuration.slimerjs) end |
Instance Attribute Details
#configuration ⇒ Object
Returns the value of attribute configuration.
5 6 7 |
# File 'lib/yabbie/slimer.rb', line 5 def configuration @configuration end |
#error ⇒ Object (readonly)
Returns the value of attribute error.
6 7 8 |
# File 'lib/yabbie/slimer.rb', line 6 def error @error end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
6 7 8 |
# File 'lib/yabbie/slimer.rb', line 6 def @options end |
#result ⇒ Object (readonly)
Returns the value of attribute result.
6 7 8 |
# File 'lib/yabbie/slimer.rb', line 6 def result @result end |
#source ⇒ Object
Returns the value of attribute source.
5 6 7 |
# File 'lib/yabbie/slimer.rb', line 5 def source @source end |
Instance Method Details
#cmd ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/yabbie/slimer.rb', line 27 def cmd [ prepend_command, Yabbie.configuration.slimerjs, command_config_file, command_error_log, script, @source.to_s.shellescape, outfile, width, height, format, timeout ].join(" ").strip end |
#render(path = nil) ⇒ Object
43 44 45 46 47 |
# File 'lib/yabbie/slimer.rb', line 43 def render(path = nil) @outfile = File.(path) if path self.run @outfile end |
#run ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/yabbie/slimer.rb', line 15 def run @error = nil @result = `#{cmd}` unless $?.exitstatus == 0 @error = @result @result = nil end @result end |
#to_file(path = nil) ⇒ Object
49 50 51 52 |
# File 'lib/yabbie/slimer.rb', line 49 def to_file(path = nil) self.render(path) File.new(@outfile) end |
#to_string(path = nil) ⇒ Object
54 55 56 |
# File 'lib/yabbie/slimer.rb', line 54 def to_string(path = nil) File.open(self.render(path)).read end |