Class: Emil::ScreenScraper
- Inherits:
-
Object
- Object
- Emil::ScreenScraper
- Defined in:
- lib/emils_screen_scraper.rb
Instance Attribute Summary collapse
-
#fuzz ⇒ Object
Returns the value of attribute fuzz.
-
#url ⇒ Object
Returns the value of attribute url.
Class Method Summary collapse
Instance Method Summary collapse
- #click(x, y) ⇒ Object
- #clickImg(str, numOfClicks = 1) ⇒ Object (also: #click_img, #click_image)
- #clickImg!(strOrArray, numOfClicks = 1) ⇒ Object
- #debug ⇒ Object
- #findImage(img, fuzz = @fuzz) ⇒ Object (also: #findImg, #find_img, #find_image)
- #findImageStr(str, fuzz = @fuzz) ⇒ Object
- #image(str) ⇒ Object
-
#initialize(url = "bilder") ⇒ ScreenScraper
constructor
A new instance of ScreenScraper.
Constructor Details
#initialize(url = "bilder") ⇒ ScreenScraper
12 13 14 15 16 |
# File 'lib/emils_screen_scraper.rb', line 12 def initialize(url="bilder") @url=url @auto = WIN32OLE.new("AutoItX3.Control") @fuzz = 0.1 end |
Instance Attribute Details
#fuzz ⇒ Object
Returns the value of attribute fuzz.
10 11 12 |
# File 'lib/emils_screen_scraper.rb', line 10 def fuzz @fuzz end |
#url ⇒ Object
Returns the value of attribute url.
10 11 12 |
# File 'lib/emils_screen_scraper.rb', line 10 def url @url end |
Class Method Details
.bitmap2img(array) ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'lib/emils_screen_scraper.rb', line 27 def ScreenScraper.bitmap2img(array) ilist = Magick::ImageList.new i = ilist.from_blob(array[2]) rescue nil if i i[0] else nil end end |
Instance Method Details
#click(x, y) ⇒ Object
22 23 24 25 |
# File 'lib/emils_screen_scraper.rb', line 22 def click(x, y) @auto.mouseMove x+5, y+5 @auto.mouseclick end |
#clickImg(str, numOfClicks = 1) ⇒ Object Also known as: click_img, click_image
82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/emils_screen_scraper.rb', line 82 def clickImg(str, numOfClicks = 1) @i = image(str) x, y = findImage(@i) if x and y numOfClicks.times{ click(x, y) sleep 0.1 } @auto.mouseMove 0,0 else nil end end |
#clickImg!(strOrArray, numOfClicks = 1) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/emils_screen_scraper.rb', line 53 def clickImg!( strOrArray, numOfClicks = 1 ) if strOrArray.class == Array has_clicked = nil while not has_clicked strOrArray.each{|str| break if has_clicked = clickImg(str, numOfClicks) } sleep 1 end else has_clicked = nil while not has_clicked has_clicked = clickImg(strOrArray, numOfClicks) sleep 1 end end has_clicked end |
#debug ⇒ Object
18 19 20 |
# File 'lib/emils_screen_scraper.rb', line 18 def debug # yield end |
#findImage(img, fuzz = @fuzz) ⇒ Object Also known as: findImg, find_img, find_image
42 43 44 45 46 47 48 49 50 51 |
# File 'lib/emils_screen_scraper.rb', line 42 def findImage(img, fuzz = @fuzz) screen = ScreenScraper.bitmap2img(Win32::Screenshot.desktop) screen.fuzz = fuzz debug{ screen.write("debug/screen.tif") img.write("debug/img.tif") } imgCoords = screen.find_similar_region(img) [imgCoords[0], imgCoords[1]] rescue nil end |
#findImageStr(str, fuzz = @fuzz) ⇒ Object
37 38 39 40 |
# File 'lib/emils_screen_scraper.rb', line 37 def findImageStr(str, fuzz = @fuzz) img = image(str) findImage(img, fuzz) end |
#image(str) ⇒ Object
72 73 74 75 76 77 78 79 80 |
# File 'lib/emils_screen_scraper.rb', line 72 def image(str) begin img = Magick::Image::read(str).first rescue img = Magick::Image::read("#{@url}/#{str}").first end p "Hittade inte bilden #{str}" unless img img end |