Sha256: 8333b93dbb502a69e6ccd3582d2ea3f68366f0a8a662475edc3699465c601e25
Contents?: true
Size: 635 Bytes
Versions: 1
Compression:
Stored size: 635 Bytes
Contents
require "string_calculator/version" module StringCalculator def manipulate return 0 if empty? raise_if_negatives_present if include?("-") return array_sum end def delimiter ',' end def digits gsub(regular_expression,delimiter).split(delimiter).reject(&:empty?).map(&:to_i) end def raise_if_negatives_present negativies = digits.select{|x| x < 0} raise "Negativies not allowed:#{negativies.join(',')}" if negativies.any? end def array_sum sum = 0 digits.each { |x| sum+=x if x < 1001 } sum end def regular_expression /[\n`~!@#$%^&*()_|+\=?;:'",.<>\{\}\[\]\\\/]/ end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
string_calculator-0.1.0 | lib/string_calculator.rb |