In Files

Files

Bullshit::ModuleFunctions

Public Instance Methods

angle(degree) click to toggle source

Return the angle degree in radians.

# File lib/bullshit.rb, line 161
    def angle(degree)
      Math.tan(Math::PI * degree / 180)
    end
array_window(array, window_size) click to toggle source

Let a window of size window_size slide over the array array and yield to the window array.

# File lib/bullshit.rb, line 172
    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) click to toggle source

Return the percentage number as a value in the range 0..1.

# File lib/bullshit.rb, line 166
    def percent(number)
      number / 100.0
    end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.