Sha256: 21dc4493328a2f93a628d2045a698901718a4fcbc1c3b54a9dffaec3056fcd03

Contents?: true

Size: 894 Bytes

Versions: 4

Compression:

Stored size: 894 Bytes

Contents

require "googlecharts"
require "launchy"

class Reputation
  class Functions
    module Mixin
      
      # Produces the URL for a google chart of the function
      #
      def google_chart_url
        points = 1000
        range = Array.new(points){|i| (i-points/2) * 0.01 }
        y = range.map{|x| f(x) }
        c = Googlecharts.line(
          :size => '800x200',
          :axis_with_labels => 'x,y',
          :title => self.class.name,
          :data => y,
          :axis_range => [[range.first,range.last],[y.min,y.max]]
        )
      end
      
      # Opens the google chart for the function in the browser
      #
      def google_chart
        Launchy::Browser.run google_chart_url
      end
    
    private
      
      def limit(r)
        if r > 1
          1
        elsif r < -1
          -1
        else
          r
        end
      end
      
    end
    
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
reputation-0.0.5 lib/reputation/functions/mixin.rb
reputation-0.0.4 lib/reputation/functions/mixin.rb
reputation-0.0.3 lib/reputation/functions/mixin.rb
reputation-0.0.2 lib/reputation/functions/mixin.rb