lib/siege/results.rb in bombard-0.0.4 vs lib/siege/results.rb in bombard-0.0.5

- old
+ new

@@ -21,30 +21,30 @@ attr_reader :transactions, :availability, :elapsed_time, :data_transferred, :response_time, :transaction_rate, :throughput, :concurrency, :failed_requests, :longest_request, :shortest_request - alias_method :failed, :failed_requests + alias_method :failed, :failed_requests alias_method :shortest, :shortest_request - alias_method :longest, :longest_request + alias_method :longest, :longest_request alias_method :response, :response_time def initialize(results) - @transactions = Integer TRANSACTIONS.match(results)[1] - @availability = Float AVAILABILITY.match(results)[1] - @elapsed_time = Float ELAPSED_TIME.match(results)[1] - @data_transferred = Float DATA_TRANSFERRED.match(results)[1] - @response_time = Float RESPONSE_TIME.match(results)[1] - @transaction_rate = Float TRANSACTION_RATE.match(results)[1] - @throughput = Float THROUGHPUT.match(results)[1] - @concurrency = Float CONCURRENCY.match(results)[1] - @failed_requests = Integer FAILED_REQUESTS.match(results)[1] - @longest_request = Float LONGEST_REQUEST.match(results)[1] - @shortest_request = Float SHORTEST_REQUEST.match(results)[1] + @transactions = Integer parse(:transactions) + @availability = Float parse(:availability) + @elapsed_time = Float parse(:elapsed_time) + @data_transferred = Float parse(:data_transferred) + @response_time = Float parse(:response_time) + @transaction_rate = Float parse(:transaction_rate) + @throughput = Float parse(:throughput) + @concurrency = Float parse(:concurrency) + @failed_requests = Integer parse(:failed_requests) + @longest_request = Float parse(:longest_request) + @shortest_request = Float parse(:shortest_request) @results = results rescue ArgumentError => e - (e.message.include?('invalid value')) ? abort("A Siege error cccurred:\n#{results}") : raise(e) + (e.message.include?('invalid value')) ? dump_results : raise(e) end def[](key) to_h.fetch(key) end @@ -65,8 +65,17 @@ concurrency: @concurrency, failed_requests: @failed_requests, longest_request: @longest_request, shortest_request: @shortest_request } + end + + def parse(const) + dump_results unless match = const_get(const).match(results) + match[1] + end + + def dump_results + abort "A Siege error occurred:\n#@results" end end end