Class: Crabfarm::Live::Viewer

Inherits:
Object
  • Object
show all
Defined in:
lib/crabfarm/live/viewer.rb

Constant Summary collapse

INJECTION_TM =

seconds

5

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(_driver) ⇒ Viewer

Returns a new instance of Viewer.



13
14
15
16
# File 'lib/crabfarm/live/viewer.rb', line 13

def initialize(_driver)
  @driver = _driver
  @injected = false
end

Instance Attribute Details

#driverObject (readonly)

Returns the value of attribute driver.



11
12
13
# File 'lib/crabfarm/live/viewer.rb', line 11

def driver
  @driver
end

Instance Method Details

#resetObject



23
24
25
26
# File 'lib/crabfarm/live/viewer.rb', line 23

def reset
  driver.get 'https://www.crabtrap.io/instructions.html'
  @injected = false
end

#show_content(_content) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/crabfarm/live/viewer.rb', line 33

def show_content(_content)
  temp_file = Tempfile.new 'cb_live'
  temp_file.write _content
  temp_file.close

  begin
    show_file temp_file.path # block requests? not sure
  ensure
    temp_file.unlink
  end
end

#show_file(_path) ⇒ Object



28
29
30
31
# File 'lib/crabfarm/live/viewer.rb', line 28

def show_file(_path)
  driver.get "file://#{_path}"
  @injected = false
end

#show_message(_status, _title, _subtitle, _content = nil, _content_type = :text) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/crabfarm/live/viewer.rb', line 45

def show_message(_status, _title, _subtitle, _content=nil, _content_type=:text)
  inject_web_tools
  Utils::Console.trap_errors 'loading web dialog' do
    driver.execute_script(
      "window.crabfarm.showDialog.apply(null, arguments);",
      _status.to_s,
      _title,
      _subtitle,
      _content,
      _content_type.to_s
    );
  end
end

#show_selector_gadgetObject



59
60
61
62
63
64
65
66
# File 'lib/crabfarm/live/viewer.rb', line 59

def show_selector_gadget
  inject_web_tools
  Utils::Console.trap_errors 'loading selector gadget' do
    driver.execute_script(
      'window.crabfarm.showSelectorGadget();'
    )
  end
end

#welcomeObject



18
19
20
21
# File 'lib/crabfarm/live/viewer.rb', line 18

def welcome
  driver.get 'https://www.crabtrap.io/welcome.html'
  @injected = false
end