Module: Eventsims
- Defined in:
- lib/eventsims.rb,
lib/eventsims/randgen.rb,
lib/eventsims/version.rb,
lib/eventsims/discrete.rb,
lib/eventsims/simevent.rb
Defined Under Namespace
Classes: Calculate, Generate, Randomsim, Simulate
Constant Summary collapse
- VERSION =
"0.0.2"
Class Method Summary collapse
- .trimlist(*args) ⇒ Object
-
.trimval(thelist) ⇒ Object
Removes leading zeros after decimal and/or approximate to 4dp.
Class Method Details
.trimlist(*args) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/eventsims/discrete.rb', line 24 def self.trimlist(*args) ''' Takes in number list or float and removes leading zeros ''' store = [] values = [] args.each{|mylist| a = [] mylist.each{|x| if x.is_a?(Float) a.push(x.round(4)) elsif x.is_a?(Array) inner = [] x.each{|y| inner.push y.is_a?(Float)? y.round(4) : y} a.push(inner) else a.push(x) end } values.push(a) } store.push(values) return store[0] end |
.trimval(thelist) ⇒ Object
Removes leading zeros after decimal and/or approximate to 4dp
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/eventsims/discrete.rb', line 5 def self.trimval(thelist) ''' Takes in number list or float and removes leading zeros ''' #Checks if passed argument is a list if thelist.is_a?(Array) temp = [] # Loops through each list and convert to 4dp if needed thelist.each{|i| temp.push i.is_a?(Float)? i.round(4) : i} thelist = temp return thelist elsif thelist.is_a?(Float) return thelist.round(4) else return thelist end end |