-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
112 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,3 +19,5 @@ jobs: | |
run: bundle install | ||
- name: Run cops | ||
run: bundle exec rubocop | ||
- name: Run test | ||
run: rake test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.DS_Store | ||
.byebug_history | ||
.examples/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,4 +4,7 @@ source 'https://rubygems.org' | |
|
||
gemspec | ||
|
||
gem 'byebug' | ||
gem 'minitest' | ||
gem 'rubocop' | ||
gem 'rubocop-minitest' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rake/testtask' | ||
require_relative 'lib/boaw/version' | ||
|
||
Rake::TestTask.new(:test) do |t| | ||
t.libs << 'test' | ||
t.libs << 'lib' | ||
t.test_files = FileList['test/**/*_test.rb'] | ||
end | ||
|
||
task :build_and_push do | ||
puts "build boaw #{Boaw::VERSION}" | ||
system 'gem build boaw.gemspec' | ||
file_name = "boaw-#{Boaw::VERSION}.gem" | ||
system "gem push #{file_name} -k rubygems" | ||
File.delete(file_name) | ||
puts 'done' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
# frozen_string_literal: true | ||
|
||
class Boaw | ||
VERSION = '0.0.2' | ||
VERSION = '0.0.3' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,22 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative 'position_parser' | ||
|
||
module Xdotool | ||
# Xdotool adapter for mouse control | ||
class Adapter | ||
def position | ||
system('xdotool getmouselocation>temp.txt') | ||
|
||
current_position = parse_position | ||
output = IO.popen('xdotool getmouselocation', &:read) | ||
|
||
{ | ||
x: current_position['x'].to_i, | ||
y: current_position['y'].to_i | ||
} | ||
PositionParser.parse(output) | ||
end | ||
|
||
def left_click(position) | ||
system("xdotool mousemove #{position[:x]} #{position[:y]} click 1") | ||
end | ||
|
||
private | ||
|
||
def parse_position | ||
file = File.open('./temp.txt', 'r') | ||
position = file.gets.scan(/(\w+):(\d+)/).to_h | ||
file.close | ||
delete_temp_file | ||
position | ||
Kernel.system("xdotool mousemove #{position[:x]} #{position[:y]} click 1") | ||
end | ||
|
||
def delete_temp_file | ||
File.delete('./temp.txt') | ||
def right_click(position) | ||
Kernel.system("xdotool mousemove #{position[:x]} #{position[:y]} click 3") | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# frozen_string_literal: true | ||
|
||
module Xdotool | ||
# coordinate position parser from Xdotool | ||
class PositionParser | ||
def self.parse(position) | ||
hash_position = position.scan(/(\w+):(\d+)/).to_h | ||
|
||
{ | ||
x: hash_position['x'].to_i, | ||
y: hash_position['y'].to_i | ||
} | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'minitest/autorun' | ||
require_relative '../test_helper' | ||
|
||
class BoawTest < Minitest::Test | ||
def setup | ||
@mock_adapter = Minitest::Mock.new | ||
@boaw = Boaw.new | ||
@boaw.instance_variable_set(:@adapter, @mock_adapter) | ||
@position = { x: 1, y: 2 } | ||
end | ||
|
||
def test_position | ||
@mock_adapter.expect(:position, @position) | ||
|
||
assert_equal @position, @boaw.position | ||
|
||
@mock_adapter.verify | ||
end | ||
|
||
def test_left_click | ||
position = @position | ||
|
||
@mock_adapter.expect(:left_click, nil, [position]) | ||
|
||
@boaw.left_click(position) | ||
|
||
@mock_adapter.verify | ||
end | ||
|
||
def test_right_click | ||
position = @position | ||
|
||
@mock_adapter.expect(:right_click, nil, [position]) | ||
|
||
@boaw.right_click(position) | ||
|
||
@mock_adapter.verify | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative '../lib/boaw' |