Class: ClipboardMonitor::ClipboardInternal
- Inherits:
-
Object
- Object
- ClipboardMonitor::ClipboardInternal
- Defined in:
- lib/clipboard_monitor/clipboard_internal.rb
Instance Attribute Summary collapse
-
#emitter ⇒ Object
Returns the value of attribute emitter.
-
#last_text ⇒ Object
Returns the value of attribute last_text.
-
#scheduler ⇒ Object
Returns the value of attribute scheduler.
Instance Method Summary collapse
- #check_text_change ⇒ Object
- #clipboard_text ⇒ Object
-
#initialize ⇒ ClipboardInternal
constructor
A new instance of ClipboardInternal.
- #start_monitoring ⇒ Object
- #stop_monitoring ⇒ Object
- #watch_for_text(&block) ⇒ Object
Constructor Details
#initialize ⇒ ClipboardInternal
Returns a new instance of ClipboardInternal.
8 9 10 11 12 |
# File 'lib/clipboard_monitor/clipboard_internal.rb', line 8 def initialize self.last_text = clipboard_text self.emitter = Emittr::Emitter.new self.scheduler = Rufus::Scheduler.new(frequency: '.2s') end |
Instance Attribute Details
#emitter ⇒ Object
Returns the value of attribute emitter.
7 8 9 |
# File 'lib/clipboard_monitor/clipboard_internal.rb', line 7 def emitter @emitter end |
#last_text ⇒ Object
Returns the value of attribute last_text.
7 8 9 |
# File 'lib/clipboard_monitor/clipboard_internal.rb', line 7 def last_text @last_text end |
#scheduler ⇒ Object
Returns the value of attribute scheduler.
7 8 9 |
# File 'lib/clipboard_monitor/clipboard_internal.rb', line 7 def scheduler @scheduler end |
Instance Method Details
#check_text_change ⇒ Object
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/clipboard_monitor/clipboard_internal.rb', line 19 def check_text_change current_text = clipboard_text if current_text == last_text return false else puts "Change" self.last_text = current_text return current_text end end |
#clipboard_text ⇒ Object
13 14 15 |
# File 'lib/clipboard_monitor/clipboard_internal.rb', line 13 def clipboard_text return Clipboard.paste.strip end |
#start_monitoring ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/clipboard_monitor/clipboard_internal.rb', line 35 def start_monitoring scheduler.every '.2s', overlap: false do result = check_text_change emitter.emit :clipboard_text_changed, result if result end scheduler.join end |
#stop_monitoring ⇒ Object
16 17 18 |
# File 'lib/clipboard_monitor/clipboard_internal.rb', line 16 def stop_monitoring scheduler.shutdown end |
#watch_for_text(&block) ⇒ Object
29 30 31 32 33 34 |
# File 'lib/clipboard_monitor/clipboard_internal.rb', line 29 def watch_for_text(&block) emitter.on :clipboard_text_changed do |contents| block.call(contents) end start_monitoring end |