Class: Yabbie::Slimer

Inherits:
Object
  • Object
show all
Defined in:
lib/yabbie/slimer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url_or_file, options = {}) ⇒ Slimer

Returns a new instance of Slimer.

Raises:



8
9
10
11
12
13
# File 'lib/yabbie/slimer.rb', line 8

def initialize(url_or_file, options = {})
  @source  = Source.new(url_or_file)
  @options = Yabbie.configuration.default_options.merge(options)

  raise NoExecutableError.new unless File.exists?(Yabbie.configuration.slimerjs)
end

Instance Attribute Details

#configurationObject

Returns the value of attribute configuration.



5
6
7
# File 'lib/yabbie/slimer.rb', line 5

def configuration
  @configuration
end

#errorObject (readonly)

Returns the value of attribute error.



6
7
8
# File 'lib/yabbie/slimer.rb', line 6

def error
  @error
end

#optionsObject (readonly)

Returns the value of attribute options.



6
7
8
# File 'lib/yabbie/slimer.rb', line 6

def options
  @options
end

#resultObject (readonly)

Returns the value of attribute result.



6
7
8
# File 'lib/yabbie/slimer.rb', line 6

def result
  @result
end

#sourceObject

Returns the value of attribute source.



5
6
7
# File 'lib/yabbie/slimer.rb', line 5

def source
  @source
end

Instance Method Details

#cmdObject



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.expand_path(path) if path
  self.run
  @outfile
end

#runObject



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