Class: Grada::Gnuplot::Plot
- Inherits:
-
Object
- Object
- Grada::Gnuplot::Plot
- Defined in:
- lib/grada/types/gnuplot.rb
Constant Summary collapse
- QUOTED_METHODS =
[ "title", "output", "xlabel", "x2label", "ylabel", "y2label", "clabel", "cblabel", "zlabel" ]
Instance Attribute Summary collapse
-
#arbitrary_lines ⇒ Object
Returns the value of attribute arbitrary_lines.
-
#cmd ⇒ Object
Returns the value of attribute cmd.
-
#data ⇒ Object
Returns the value of attribute data.
-
#settings ⇒ Object
Returns the value of attribute settings.
-
#styles ⇒ Object
Returns the value of attribute styles.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize ⇒ Plot
constructor
A new instance of Plot.
- #method_missing(meth, *args) ⇒ Object
- #set(var, value = "") ⇒ Object
- #store_datasets(io = '') ⇒ Object
- #to_gplot(io = '') ⇒ Object
- #unset(var) ⇒ Object
Constructor Details
#initialize ⇒ Plot
Returns a new instance of Plot.
71 72 73 74 75 76 |
# File 'lib/grada/types/gnuplot.rb', line 71 def initialize @settings = [] @arbitrary_lines = [] @data = [] @styles = [] end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args) ⇒ Object
86 87 88 |
# File 'lib/grada/types/gnuplot.rb', line 86 def method_missing(meth, *args) set meth.id2name, *args end |
Instance Attribute Details
#arbitrary_lines ⇒ Object
Returns the value of attribute arbitrary_lines.
67 68 69 |
# File 'lib/grada/types/gnuplot.rb', line 67 def arbitrary_lines @arbitrary_lines end |
#cmd ⇒ Object
Returns the value of attribute cmd.
67 68 69 |
# File 'lib/grada/types/gnuplot.rb', line 67 def cmd @cmd end |
#data ⇒ Object
Returns the value of attribute data.
67 68 69 |
# File 'lib/grada/types/gnuplot.rb', line 67 def data @data end |
#settings ⇒ Object
Returns the value of attribute settings.
67 68 69 |
# File 'lib/grada/types/gnuplot.rb', line 67 def settings @settings end |
#styles ⇒ Object
Returns the value of attribute styles.
67 68 69 |
# File 'lib/grada/types/gnuplot.rb', line 67 def styles @styles end |
Class Method Details
.construct(&block) ⇒ Object
78 79 80 81 82 83 84 |
# File 'lib/grada/types/gnuplot.rb', line 78 def self.construct(&block) plot = new block.call plot if block_given? { plot_settings: plot.to_gplot, plot_data: plot.store_datasets } end |
Instance Method Details
#set(var, value = "") ⇒ Object
90 91 92 93 |
# File 'lib/grada/types/gnuplot.rb', line 90 def set ( var, value = "" ) value = "\"#{value}\"" if QUOTED_METHODS.include? var unless value =~ /^'.*'$/ @settings << [ :set, var, value ] end |
#store_datasets(io = '') ⇒ Object
107 108 109 110 111 112 113 114 |
# File 'lib/grada/types/gnuplot.rb', line 107 def store_datasets(io = '') if @data.size > 0 io += 'plot' + " #{ @data.map { |element| element.plot_args }.join(', ') } \n" io += @data.map { |ds| ds.to_gplot }.compact.join("\n") + "\n" end io end |
#to_gplot(io = '') ⇒ Object
99 100 101 102 103 104 105 |
# File 'lib/grada/types/gnuplot.rb', line 99 def to_gplot(io = '') @settings.each { |setting| io += setting.map(&:to_s).join(' ') + "\n" } @styles.each{ |style| io += style.to_s + "\n" } @arbitrary_lines.each{ |line| io += line + "\n" } io end |
#unset(var) ⇒ Object
95 96 97 |
# File 'lib/grada/types/gnuplot.rb', line 95 def unset (var) @settings << [ :unset, var ] end |