Class: Result
- Inherits:
-
Object
- Object
- Result
- Defined in:
- lib/teuton/case_manager/case/result/result.rb,
lib/teuton/case_manager/case/result/ext_array.rb,
lib/teuton/case_manager/case/result/ext_filter.rb,
lib/teuton/case_manager/case/result/ext_compare.rb
Overview
This is an extension of Result class rubocop:disable Metrics/ClassLength
Instance Attribute Summary collapse
-
#content ⇒ Object
Returns the value of attribute content.
-
#exitstatus ⇒ Object
Returns the value of attribute exitstatus.
Instance Method Summary collapse
- #alterations ⇒ Object
- #contain?(value) ⇒ Boolean
- #count ⇒ Object (also: #count!, #length, #len, #size)
- #debug ⇒ Object
- #empty ⇒ Object (also: #empty?)
-
#eq(input) ⇒ Object
(also: #eq?, #equal, #equal?, #is_equal?)
rubocop:disable Metrics/MethodLength Return true when content is equal than input.
- #expected ⇒ Object
-
#find(filter) ⇒ Object
(also: #grep, #grep!, #find!)
TODO: Error line 102 undefined include? method for 0 Fixnum…
-
#ge(input) ⇒ Object
(also: #greater_or_equal, #greater_or_equal?)
rubocop:disable Metrics/MethodLength.
-
#gt(input) ⇒ Object
(also: #greater, #greater_than)
rubocop:disable Metrics/MethodLength.
- #include?(value) ⇒ Boolean
-
#initialize ⇒ Result
constructor
A new instance of Result.
-
#le(input) ⇒ Object
(also: #lesser_or_equal, #lesser_or_equal?)
rubocop:disable Metrics/MethodLength.
-
#lt(input) ⇒ Object
(also: #lesser, #smaller, #lesser_than)
rubocop:disable Metrics/MethodLength.
-
#near_to?(input) ⇒ Boolean
(also: #near_to, #near?, #near)
Return 'true' if the parameter value is near to the target value.
-
#neq(external) ⇒ Object
(also: #neq?, #not_equal, #not_equal?)
rubocop:disable Metrics/MethodLength.
- #not_find(p_filter) ⇒ Object (also: #grep_v)
- #not_include?(value) ⇒ Boolean
- #ok? ⇒ Boolean
- #reset ⇒ Object
- #restore ⇒ Object (also: #restore!)
- #since(filter) ⇒ Object
- #until(filter) ⇒ Object
- #value ⇒ Object
Constructor Details
#initialize ⇒ Result
Returns a new instance of Result.
20 21 22 |
# File 'lib/teuton/case_manager/case/result/result.rb', line 20 def initialize reset end |
Instance Attribute Details
#content ⇒ Object
Returns the value of attribute content.
17 18 19 |
# File 'lib/teuton/case_manager/case/result/result.rb', line 17 def content @content end |
#exitstatus ⇒ Object
Returns the value of attribute exitstatus.
18 19 20 |
# File 'lib/teuton/case_manager/case/result/result.rb', line 18 def exitstatus @exitstatus end |
Instance Method Details
#alterations ⇒ Object
24 25 26 |
# File 'lib/teuton/case_manager/case/result/result.rb', line 24 def alterations @alterations.join(' & ') end |
#contain?(value) ⇒ Boolean
28 29 30 31 |
# File 'lib/teuton/case_manager/case/result/ext_array.rb', line 28 def contain?(value) @expected = "Contain <#{value}> value" @content.contain? value end |
#count ⇒ Object Also known as: count!, length, len, size
5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/teuton/case_manager/case/result/ext_array.rb', line 5 def count @alterations << 'count' if @content.class == Array @content = [@content.count] self elsif @content.nil? @content = ['0'] else @content = [@content.to_i.to_s] end self end |
#debug ⇒ Object
42 43 44 45 46 47 48 49 50 |
# File 'lib/teuton/case_manager/case/result/result.rb', line 42 def debug print "\n" + '*' * 20 print " [DEBUG] count=#{@content.count} " puts '*' * 20 @content.each_with_index do |item, index| puts format('%<index>2d: %<item>s', { index: index, item: item }) end puts '*' * 57 end |
#empty ⇒ Object Also known as: empty?
33 34 35 36 |
# File 'lib/teuton/case_manager/case/result/ext_array.rb', line 33 def empty @expected = 'Empty!' @content.empty end |
#eq(input) ⇒ Object Also known as: eq?, equal, equal?, is_equal?
rubocop:disable Metrics/MethodLength Return true when content is equal than input
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/teuton/case_manager/case/result/ext_compare.rb', line 9 def eq(input) @expected = input case input.class.to_s when 'Fixnum' value = @content[0].to_i puts '[WARN] Fixnum class is deprecated!' puts ' Upgrade your Ruby version.' when 'Float' value = @content[0].to_f when 'Integer' value = @content[0].to_i when 'String' value = @content[0].to_s else value = @content[0] end value == input end |
#expected ⇒ Object
52 53 54 |
# File 'lib/teuton/case_manager/case/result/result.rb', line 52 def expected @expected.to_s end |
#find(filter) ⇒ Object Also known as: grep, grep!, find!
TODO: Error line 102 undefined include? method for 0 Fixnum…
6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/teuton/case_manager/case/result/ext_filter.rb', line 6 def find(filter) @alterations << "find(#{filter})" case filter.class.to_s when 'Array' find_when_array(filter) when 'String' || 'Integer' @content.select! { |i| i.include?(filter.to_s) } when 'Regexp' @content.select! { |i| filter.match(i) } end self end |
#ge(input) ⇒ Object Also known as: greater_or_equal, greater_or_equal?
rubocop:disable Metrics/MethodLength
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/teuton/case_manager/case/result/ext_compare.rb', line 58 def ge(input) @expected = "Greater or equal to #{input}" return false if @content.nil? || @content[0].nil? value = @content[0] case input.class.to_s when 'Fixnum' value = @content[0].to_i puts '[WARN] Fixnum class is deprecated!' puts ' Upgrade your Ruby version.' when 'Float' value = @content[0].to_f when 'Integer' value = @content[0].to_i end value >= input end |
#gt(input) ⇒ Object Also known as: greater, greater_than
rubocop:disable Metrics/MethodLength
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/teuton/case_manager/case/result/ext_compare.rb', line 80 def gt(input) @expected = "Greater than #{input}" return false if @content.nil? || @content[0].nil? value = @content[0] case input.class.to_s when 'Fixnum' value = @content[0].to_i puts '[WARN] Fixnum class is deprecated!' puts ' Upgrade your Ruby version.' when 'Float' value = @content[0].to_f when 'Integer' value = @content[0].to_i end value > input end |
#include?(value) ⇒ Boolean
18 19 20 21 |
# File 'lib/teuton/case_manager/case/result/ext_array.rb', line 18 def include?(value) @expected = "Include <#{value}> value" @content[0].include?(value) end |
#le(input) ⇒ Object Also known as: lesser_or_equal, lesser_or_equal?
rubocop:disable Metrics/MethodLength
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/teuton/case_manager/case/result/ext_compare.rb', line 102 def le(input) @expected = "Lesser or equal to #{input}" return false if @content.nil? || @content[0].nil? value = @content[0] case input.class.to_s when 'Fixnum' value = @content[0].to_i puts '[WARN] Fixnum class is deprecated!' puts ' Upgrade your Ruby version.' when 'Float' value = @content[0].to_f when 'Integer' value = @content[0].to_i end value <= input end |
#lt(input) ⇒ Object Also known as: lesser, smaller, lesser_than
rubocop:disable Metrics/MethodLength
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/teuton/case_manager/case/result/ext_compare.rb', line 125 def lt(input) @expected = "Lesser than #{input}" return false if @content.nil? || @content[0].nil? value = @content[0] case input.class.to_s when 'Fixnum' value = @content[0].to_i puts '[WARN] Fixnum class is deprecated!' puts ' Upgrade your Ruby version.' when 'Float' value = @content[0].to_f when 'Integer' value = @content[0].to_i end value < input end |
#near_to?(input) ⇒ Boolean Also known as: near_to, near?, near
Return 'true' if the parameter value is near to the target value. To get this we consider a 10% desviation or less, as an acceptable result.
149 150 151 152 153 154 155 156 157 158 |
# File 'lib/teuton/case_manager/case/result/ext_compare.rb', line 149 def near_to?(input) @expected = "Is near to #{input}" return false if @content.nil? target = @content[0].to_f desv = (target * 10.0) / 100.0 return true if (target - input.to_f).abs.to_f <= desv false end |
#neq(external) ⇒ Object Also known as: neq?, not_equal, not_equal?
rubocop:disable Metrics/MethodLength
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/teuton/case_manager/case/result/ext_compare.rb', line 35 def neq(external) @expected = "Not equal to #{external}" case external.class.to_s when 'Fixnum' internal = @content[0].to_i puts '[WARN] Fixnum class is deprecated!' puts ' Upgrade your Ruby version.' when 'Float' internal = @content[0].to_f when 'Integer' internal = @content[0].to_i else internal = @content[0] end internal != external end |
#not_find(p_filter) ⇒ Object Also known as: grep_v
22 23 24 25 26 27 28 |
# File 'lib/teuton/case_manager/case/result/ext_filter.rb', line 22 def not_find(p_filter) @alterations << "not_find(#{p_filter})" return self if @content.size.zero? @content.reject! { |i| i.include?(p_filter) } self end |
#not_include?(value) ⇒ Boolean
23 24 25 26 |
# File 'lib/teuton/case_manager/case/result/ext_array.rb', line 23 def not_include?(value) @expected = "Not include <#{value}> value" !@content[0].include?(value) end |
#ok? ⇒ Boolean
56 57 58 59 60 |
# File 'lib/teuton/case_manager/case/result/result.rb', line 56 def ok? return false if @exitstatus.nil? @exitstatus.zero? end |
#reset ⇒ Object
33 34 35 36 37 38 39 40 |
# File 'lib/teuton/case_manager/case/result/result.rb', line 33 def reset @content_backup = [] @content = [] @exitstatus = nil @value = nil @expected = nil @alterations = [] end |
#restore ⇒ Object Also known as: restore!
62 63 64 65 66 67 |
# File 'lib/teuton/case_manager/case/result/result.rb', line 62 def restore temp = @content_backup.clone reset @content_backup = temp @content = temp.clone end |
#since(filter) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/teuton/case_manager/case/result/ext_filter.rb', line 31 def since(filter) @alterations << "since(#{filter})" return self if @content.size.zero? if filter.class == String flag = false @content.select! do |i| flag = true if i.include?(filter.to_s) flag end end self end |
#until(filter) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/teuton/case_manager/case/result/ext_filter.rb', line 45 def until(filter) @alterations << "until(#{filter})" return self if @content.size.zero? if filter.class == String flag = true @content.select! do |i| flag = false if i.include?(filter.to_s) flag end end self end |
#value ⇒ Object
70 71 72 |
# File 'lib/teuton/case_manager/case/result/result.rb', line 70 def value @content[0] end |