Top Level Namespace
Instance Method Summary collapse
- #blue(text) ⇒ Object
- #colorize(text, color_code) ⇒ Object
- #cyan(text) ⇒ Object
- #diff(query, action, options = {removed:true, added:true}) ⇒ Object
- #get_roots ⇒ Object
- #green(text) ⇒ Object
- #items_added(query, action) ⇒ Object
- #items_removed(query, action) ⇒ Object
- #magenta(text) ⇒ Object
- #print_tree(options = {}) ⇒ Object
- #print_tree_recurse(query, node, indent, show_class, show_index) ⇒ Object
- #red(text) ⇒ Object
- #roots_with_value(node) ⇒ Object
- #yellow(text) ⇒ Object
Instance Method Details
#blue(text) ⇒ Object
93 94 95 |
# File 'lib/xamarin-automators-calabash.rb', line 93 def blue(text) colorize(text, 34) end |
#colorize(text, color_code) ⇒ Object
85 86 87 |
# File 'lib/xamarin-automators-calabash.rb', line 85 def colorize(text, color_code) "\e[#{color_code}m#{text}\e[0m" end |
#cyan(text) ⇒ Object
101 102 103 |
# File 'lib/xamarin-automators-calabash.rb', line 101 def cyan(text) colorize(text, 36) end |
#diff(query, action, options = {removed:true, added:true}) ⇒ Object
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/xamarin-automators-calabash.rb', line 113 def diff(query, action, ={removed:true, added:true}) items1 = query[] action[] sleep(1) items2 = query[] items1.map {|x| x.delete("description")} items2.map {|x| x.delete("description")} added = items2 - items1 removed = items1 - items2 if [:added] puts green("=====ITEMS ADDED=====") awesome_print(added) end if [:removed] puts red("=====ITEMS REMOVED=====") awesome_print(removed) end nil end |
#get_roots ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/xamarin-automators-calabash.rb', line 5 def get_roots @all_items = query "*" @all_items.map {|x| x.delete("description")} roots = Hash.new roots[0] = @all_items[0] print "Found root(s) at: 0" (1..(@all_items.count-1)).each do |i| parents_children = query("* index:#{i} parent * index:0 child *") parents_children.map {|x| x.delete("description")} unless parents_children.include? @all_items[i] print ", #{i}" parent = query("* index:#{i} parent * index:0").first unless parent.nil? parent.delete("description") end roots[i] = parent end end print "\n" return roots end |
#green(text) ⇒ Object
105 106 107 |
# File 'lib/xamarin-automators-calabash.rb', line 105 def green(text) colorize(text, 32) end |
#items_added(query, action) ⇒ Object
133 134 135 |
# File 'lib/xamarin-automators-calabash.rb', line 133 def items_added(query, action) diff(query, action, removed:false, added:true) end |
#items_removed(query, action) ⇒ Object
137 138 139 |
# File 'lib/xamarin-automators-calabash.rb', line 137 def items_removed(query, action) diff(query, action, removed:true, added:false) end |
#magenta(text) ⇒ Object
97 98 99 |
# File 'lib/xamarin-automators-calabash.rb', line 97 def magenta(text) colorize(text, 35) end |
#print_tree(options = {}) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/xamarin-automators-calabash.rb', line 27 def print_tree(={}) = { :show_class => false, :show_index => false } = .merge() show_class = [:show_class] show_index = [:show_index] puts "Finding roots..." @roots = get_roots @count = 1 main_root = @roots[0] @roots.delete(0) print_tree_recurse("* index:0", (query "* index:0").first, 0, show_class, show_index) @roots.each do |key, value| @count += 1 puts "#{magenta("** Parent off of screen **")}" print_tree_recurse("* index:#{key}", (query "* index:#{key}").first, 0, show_class, show_index) end "Found #{@count} nodes" end |
#print_tree_recurse(query, node, indent, show_class, show_index) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/xamarin-automators-calabash.rb', line 53 def print_tree_recurse(query, node, indent, show_class, show_index) node.delete("description") unless node["description"].nil? indent.times { print " " } print "id: #{green(node["id"])} " unless node["id"].nil? print "text: '#{cyan(node["text"])}' " unless node["text"].nil? if show_class or (node["id"].nil? and node["text"].nil?) print "class: #{yellow(node["class"].split(/[$.]/).last)} " end if show_index index = @all_items.index(node) print "index: #{magenta("#{index}")} " end print "\n" children = query("#{query} child *") roots = roots_with_value(node) if roots.size != 0 roots.each do |k,v| sub_root_query = "* index:#{k}" sub_root = query(sub_root_query).first @roots.delete(k) @count += 1 (indent+1).times { print " " } print "#{magenta("**")}\n" print_tree_recurse(sub_root_query, sub_root, indent+2, show_class, show_index) end end (children.size).times do |i| @count += 1 print_tree_recurse("#{query} child * index:#{i}", children[i], indent+1, show_class, show_index) end end |
#red(text) ⇒ Object
109 110 111 |
# File 'lib/xamarin-automators-calabash.rb', line 109 def red(text) colorize(text, 31) end |
#roots_with_value(node) ⇒ Object
49 50 51 |
# File 'lib/xamarin-automators-calabash.rb', line 49 def roots_with_value(node) return @roots.select {|k,v| v == node } end |
#yellow(text) ⇒ Object
89 90 91 |
# File 'lib/xamarin-automators-calabash.rb', line 89 def yellow(text) colorize(text, 33) end |