Class: UICov::ScreenData

Inherits:
Object
  • Object
show all
Defined in:
lib/uicov/coverage/screen_data.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ ScreenData

Returns a new instance of ScreenData.



8
9
10
11
12
13
14
15
# File 'lib/uicov/coverage/screen_data.rb', line 8

def initialize(name)
  @name = name
  @hits = 0
  @elements = {}
  @transitions = {}
  @actions = {}
  @checks = {}
end

Instance Attribute Details

#actionsObject (readonly)

Returns the value of attribute actions.



7
8
9
# File 'lib/uicov/coverage/screen_data.rb', line 7

def actions
  @actions
end

#checksObject (readonly)

Returns the value of attribute checks.



7
8
9
# File 'lib/uicov/coverage/screen_data.rb', line 7

def checks
  @checks
end

#elementsObject (readonly)

Returns the value of attribute elements.



7
8
9
# File 'lib/uicov/coverage/screen_data.rb', line 7

def elements
  @elements
end

#transitionsObject (readonly)

Returns the value of attribute transitions.



7
8
9
# File 'lib/uicov/coverage/screen_data.rb', line 7

def transitions
  @transitions
end

Instance Method Details

#add_action(name) ⇒ Object



30
31
32
# File 'lib/uicov/coverage/screen_data.rb', line 30

def add_action(name)
  actions[name] ||= ActionData.new name
end

#add_check(name) ⇒ Object



38
39
40
# File 'lib/uicov/coverage/screen_data.rb', line 38

def add_check(name)
  checks[name] ||= CheckData.new name
end

#add_covered_action(name) ⇒ Object



34
35
36
# File 'lib/uicov/coverage/screen_data.rb', line 34

def add_covered_action(name)
  add_action(name).hit
end

#add_covered_check(name) ⇒ Object



42
43
44
# File 'lib/uicov/coverage/screen_data.rb', line 42

def add_covered_check(name)
  add_check(name).hit
end

#add_covered_element(name) ⇒ Object



50
51
52
# File 'lib/uicov/coverage/screen_data.rb', line 50

def add_covered_element(name)
  add_element(name).hit
end

#add_covered_transition(name, to) ⇒ Object



26
27
28
# File 'lib/uicov/coverage/screen_data.rb', line 26

def add_covered_transition(name, to)
  add_transition(name, to).hit
end

#add_element(name) ⇒ Object



46
47
48
# File 'lib/uicov/coverage/screen_data.rb', line 46

def add_element(name)
  elements[name] ||= ElementData.new name
end

#add_transition(name, to) ⇒ Object



21
22
23
24
# File 'lib/uicov/coverage/screen_data.rb', line 21

def add_transition(name, to)
  tr_key = TransitionData.get_key(name, to)
  transitions[tr_key] ||= TransitionData.new name, to
end

#get_count(members_name, hitted = false) ⇒ Object



78
79
80
81
82
83
84
85
# File 'lib/uicov/coverage/screen_data.rb', line 78

def get_count(members_name, hitted=false)
  members = instance_variable_get("@#{members_name}")
  if hitted
    members.values.keep_if{ |e| 0 < e.hits}.size
  else
    members.size
  end
end

#get_coverage(members_name) ⇒ Object



71
72
73
74
75
76
# File 'lib/uicov/coverage/screen_data.rb', line 71

def get_coverage(members_name)
  members = instance_variable_get("@#{members_name}")
  uncovered = members.values.select{|e| e.hits == 0}
  cov = ((members.size.to_f - uncovered.size) / members.size) * 100
  return cov.nan? ? 100.0 : cov.round(2)
end

#hitObject



17
18
19
# File 'lib/uicov/coverage/screen_data.rb', line 17

def hit
  @hits += 1
end

#reportObject



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/uicov/coverage/screen_data.rb', line 54

def report
  %Q^
<h2>Screen: <span>#{@name}</span></h2>
<h3>Coverage summary</h3>
#{report_members_summary 'elements' unless elements.empty?}
#{report_members_summary 'transitions' unless transitions.empty?}
#{report_members_summary 'actions' unless actions.empty?}
#{report_members_summary 'checks' unless checks.empty?}
<h3>Coverage details</h3>
#{report_members 'elements' unless elements.empty?}
#{report_members 'transitions' unless transitions.empty?}
#{report_members 'actions' unless actions.empty?}
#{report_members 'checks' unless checks.empty?}
<hr/>
  ^
end