Class: Graph::Function::Only
- Inherits:
-
Object
- Object
- Graph::Function::Only
- Includes:
- PlotConfig, ReformatString
- Defined in:
- lib/graph/function/only.rb
Instance Attribute Summary collapse
-
#data_generator ⇒ Object
Returns the value of attribute data_generator.
Instance Method Summary collapse
-
#initialize(generator) ⇒ Only
constructor
A new instance of Only.
- #of(method_obj) ⇒ Object
Methods included from PlotConfig
Methods included from ReformatString
#camel_title, #escape_underscores
Constructor Details
#initialize(generator) ⇒ Only
Returns a new instance of Only.
8 9 10 |
# File 'lib/graph/function/only.rb', line 8 def initialize(generator) @data_generator = generator end |
Instance Attribute Details
#data_generator ⇒ Object
Returns the value of attribute data_generator.
6 7 8 |
# File 'lib/graph/function/only.rb', line 6 def data_generator @data_generator end |
Instance Method Details
#of(method_obj) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/graph/function/only.rb', line 12 def of(method_obj) fail unless method_obj.is_a?(Method) self.class.send(:define_method, :a, proc(&method_obj)) Gnuplot.open do |gp| Gnuplot::Plot.new(gp) do |plot| plot.title "#{title = camel_title(method_obj.name)}" set_up(plot) x = Graph::Function.configuration.step pb = ProgressBar.create(title: title, total: x.size) y = x.collect do |v| pb.increment data = data_generator.call(v) Benchmark.measure { a(data) }.real end plot.data << Gnuplot::DataSet.new( [x, y] ) do |ds| ds.with = "linespoints" ds.title = "#{escape_underscores(method_obj.name)}" end end end end |