Class: Rufus::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/rufus/parser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(json) ⇒ Parser

Returns a new instance of Parser.



7
8
9
# File 'lib/rufus/parser.rb', line 7

def initialize(json)
  @screen_data = JSON.parse(json)
end

Instance Attribute Details

#screen_dataObject (readonly)

Returns the value of attribute screen_data.



5
6
7
# File 'lib/rufus/parser.rb', line 5

def screen_data
  @screen_data
end

Instance Method Details

#child_count(label) ⇒ Object



51
52
53
# File 'lib/rufus/parser.rb', line 51

def child_count(label)
  view_by_label(label)['children'].count if found(label)
end

#class_for(label) ⇒ Object



11
12
13
# File 'lib/rufus/parser.rb', line 11

def class_for(label)
  view_by_label(label)['type'] if exists?(label)
end

#displayed?(label) ⇒ Boolean

Returns:

  • (Boolean)


45
46
47
48
49
# File 'lib/rufus/parser.rb', line 45

def displayed?(label)
  view = view_by_label(label)
  return false if view.nil?
  view_by_label(label)['visible']
end

#enabled?(label) ⇒ Boolean

Returns:

  • (Boolean)


39
40
41
42
43
# File 'lib/rufus/parser.rb', line 39

def enabled?(label)
  view = view_by_label(label)
  return false if view.nil?
  view['enabled']
end

#exists?(label) ⇒ Boolean

Returns:

  • (Boolean)


73
74
75
76
77
78
79
# File 'lib/rufus/parser.rb', line 73

def exists?(label)
  if view_by_label(label).nil?
    false
  else
    view_by_label(label)['name'].eql?(label)
  end
end

#height(label) ⇒ Object



23
24
25
# File 'lib/rufus/parser.rb', line 23

def height(label)
  view_by_label(label)['rect']['size']['height'] if exists?(label)
end

#label_for(label) ⇒ Object



35
36
37
# File 'lib/rufus/parser.rb', line 35

def label_for(label)
  view_by_label(label)['label'] if exists?(label)
end

#value(label) ⇒ Object



15
16
17
# File 'lib/rufus/parser.rb', line 15

def value(label)
  view_by_label(label)['value'] if exists?(label)
end

#view_by_label(label) ⇒ Object



55
56
57
58
59
# File 'lib/rufus/parser.rb', line 55

def view_by_label(label)
  @found_view = nil
  view_data_for(@screen_data, label)
  @found_view
end

#view_data_for(json, label) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
# File 'lib/rufus/parser.rb', line 61

def view_data_for(json, label)
  if json['name'].eql?(label)
    @found_view = json
  else
    if json['children'].count > 0
      json['children'].each do |child|
        view_data_for(child, label)
      end
    end
  end
end

#width(label) ⇒ Object



19
20
21
# File 'lib/rufus/parser.rb', line 19

def width(label)
  view_by_label(label)['rect']['size']['width'] if exists?(label)
end

#x_pos(label) ⇒ Object



27
28
29
# File 'lib/rufus/parser.rb', line 27

def x_pos(label)
  view_by_label(label)['rect']['origin']['x'] if exists?(label)
end

#y_pos(label) ⇒ Object



31
32
33
# File 'lib/rufus/parser.rb', line 31

def y_pos(label)
  view_by_label(label)['rect']['origin']['y'] if exists?(label)
end