Module: Bullshit::ModuleFunctions

Included in:
Case::CaseExtension, Case::CaseExtension::TruncateData
Defined in:
lib/bullshit.rb

Class Method Summary collapse

Class Method Details

.angle(degree) ⇒ Object

Return the angle degree in radians.



190
191
192
# File 'lib/bullshit.rb', line 190

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.



201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
# File 'lib/bullshit.rb', line 201

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.



195
196
197
# File 'lib/bullshit.rb', line 195

def percent(number)
  number / 100.0
end