Class: ListCountComparison
- Inherits:
-
Object
- Object
- ListCountComparison
- Defined in:
- lib/cucumber-rest-bdd/list.rb
Instance Method Summary collapse
- #amount ⇒ Object
- #compare(actual) ⇒ Object
-
#compare_to_string ⇒ Object
turn a comparison into a string.
-
#initialize(type, amount) ⇒ ListCountComparison
constructor
A new instance of ListCountComparison.
- #to_string ⇒ Object
- #type ⇒ Object
Constructor Details
#initialize(type, amount) ⇒ ListCountComparison
Returns a new instance of ListCountComparison.
80 81 82 83 |
# File 'lib/cucumber-rest-bdd/list.rb', line 80 def initialize(type, amount) @type = type.nil? ? CMP_EQUALS : to_compare(type) @amount = amount.nil? ? 1 : to_num(amount) end |
Instance Method Details
#amount ⇒ Object
100 101 102 |
# File 'lib/cucumber-rest-bdd/list.rb', line 100 def amount return amount end |
#compare(actual) ⇒ Object
85 86 87 88 89 90 91 92 93 94 |
# File 'lib/cucumber-rest-bdd/list.rb', line 85 def compare(actual) case @type when CMP_LESS_THAN then actual < @amount when CMP_MORE_THAN then actual > @amount when CMP_AT_MOST then actual <= @amount when CMP_AT_LEAST then actual >= @amount when CMP_EQUALS then actual == @amount else actual == @amount end end |
#compare_to_string ⇒ Object
turn a comparison into a string
105 106 107 108 109 110 111 112 113 114 |
# File 'lib/cucumber-rest-bdd/list.rb', line 105 def compare_to_string() case @type when CMP_LESS_THAN then 'fewer than ' when CMP_MORE_THAN then 'more than ' when CMP_AT_LEAST then 'at least ' when CMP_AT_MOST then 'at most ' when CMP_EQUALS then 'exactly ' else '' end end |
#to_string ⇒ Object
116 117 118 |
# File 'lib/cucumber-rest-bdd/list.rb', line 116 def to_string() return compare_to_string() + ' ' + @amount.to_s end |
#type ⇒ Object
96 97 98 |
# File 'lib/cucumber-rest-bdd/list.rb', line 96 def type return @type end |