Class: ListCountComparison

Inherits:
Object
  • Object
show all
Defined in:
lib/cucumber-rest-bdd/list.rb

Instance Method Summary collapse

Constructor Details

#initialize(type, amount) ⇒ ListCountComparison

Returns a new instance of ListCountComparison.



76
77
78
79
# File 'lib/cucumber-rest-bdd/list.rb', line 76

def initialize(type, amount)
    @type = type.nil? ? CMP_EQUALS : to_compare(type)
    @amount = amount.nil? ? 1 : to_num(amount)
end

Instance Method Details

#amountObject



96
97
98
# File 'lib/cucumber-rest-bdd/list.rb', line 96

def amount
    return amount
end

#compare(actual) ⇒ Object



81
82
83
84
85
86
87
88
89
90
# File 'lib/cucumber-rest-bdd/list.rb', line 81

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_stringObject

turn a comparison into a string



101
102
103
104
105
106
107
108
109
110
# File 'lib/cucumber-rest-bdd/list.rb', line 101

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_stringObject



112
113
114
# File 'lib/cucumber-rest-bdd/list.rb', line 112

def to_string()
    return compare_to_string() + ' ' + @amount.to_s
end

#typeObject



92
93
94
# File 'lib/cucumber-rest-bdd/list.rb', line 92

def type
    return @type
end