Module: Bullshit::ModuleFunctions
- Included in:
- Case::CaseExtension, Case::CaseExtension::TruncateData
- Defined in:
- lib/bullshit.rb
Class Method Summary collapse
-
.angle(degree) ⇒ Object
Return the angle
degree
in radians. -
.array_window(array, window_size) ⇒ Object
Let a window of size
window_size
slide over the arrayarray
and yield to the window array. -
.percent(number) ⇒ Object
Return the percentage number as a value in the range 0..1.
Class Method Details
.angle(degree) ⇒ Object
Return the angle degree
in radians.
22 23 24 |
# File 'lib/bullshit.rb', line 22 def angle(degree) Math.tan(Math::PI * degree / 180) end |
.array_window(array, window_size) ⇒ Object
Let a window of size window_size
slide over the array array
and yield to the window array.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/bullshit.rb', line 33 def array_window(array, window_size) window_size < 1 and raise ArgumentError, "window_size = #{window_size} < 1" window_size = window_size.to_i window_size += 1 if window_size % 2 == 0 radius = window_size / 2 array.each_index do |i| ws = window_size from = i - radius negative_from = false if from < 0 negative_from = true ws += from from = 0 end a = array[from, ws] if (diff = window_size - a.size) > 0 mean = a.inject(0.0) { |s, x| s + x } / a.size a = if negative_from [ mean ] * diff + a else a + [ mean ] * diff end end yield a end nil end |
.percent(number) ⇒ Object
Return the percentage number as a value in the range 0..1.
27 28 29 |
# File 'lib/bullshit.rb', line 27 def percent(number) number / 100.0 end |