Class: DbPlot
- Inherits:
-
Object
- Object
- DbPlot
- Defined in:
- lib/dbplot.rb,
lib/dbplot/runner.rb
Defined Under Namespace
Modules: Runner
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
-
#debug ⇒ Object
Returns the value of attribute debug.
-
#settings ⇒ Object
Returns the value of attribute settings.
-
#string ⇒ Object
Returns the value of attribute string.
Class Method Summary collapse
Instance Method Summary collapse
- #complete? ⇒ Boolean
- #execute ⇒ Object
-
#initialize(options = {}) ⇒ DbPlot
constructor
A new instance of DbPlot.
- #parse ⇒ Object
- #parse_line(string) ⇒ Object
- #prompt ⇒ Object
- #template_file ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ DbPlot
Returns a new instance of DbPlot.
25 26 27 28 29 |
# File 'lib/dbplot.rb', line 25 def initialize( = {}) %w(host database username password).proxy(:map).to_sym.each do |setting| settings[setting] = [setting] if [setting] end end |
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
8 9 10 |
# File 'lib/dbplot.rb', line 8 def data @data end |
#debug ⇒ Object
Returns the value of attribute debug.
8 9 10 |
# File 'lib/dbplot.rb', line 8 def debug @debug end |
#settings ⇒ Object
Returns the value of attribute settings.
8 9 10 |
# File 'lib/dbplot.rb', line 8 def settings @settings end |
#string ⇒ Object
Returns the value of attribute string.
8 9 10 |
# File 'lib/dbplot.rb', line 8 def string @string end |
Class Method Details
.version ⇒ Object
10 11 12 |
# File 'lib/dbplot.rb', line 10 def self.version "DbPlot v" + version_string end |
Instance Method Details
#complete? ⇒ Boolean
72 73 74 |
# File 'lib/dbplot.rb', line 72 def complete? @string =~ /;\s*$/ end |
#execute ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/dbplot.rb', line 35 def execute return unless complete? @query = %{SELECT #{select_string} FROM #{@table}} template = ERB.new(File.read(template_file)).result(binding) puts template if debug unless settings[:dry_run] `echo \"#{template.gsub('"', '\\"')}\" | r --no-save #{"2>&1 > /dev/null" unless debug}` end @string = nil end |
#parse ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/dbplot.rb', line 50 def parse if legal_expression? set_defaults set_file set_color_by set_facet_by else puts "\ncould not parse: \"#{string}\"\n\n" @string = nil end self end |
#parse_line(string) ⇒ Object
64 65 66 67 68 69 70 |
# File 'lib/dbplot.rb', line 64 def parse_line(string) return self if string.strip == "" @string ||= "" @string += " #{string}" parse if complete? return self end |
#prompt ⇒ Object
77 78 79 |
# File 'lib/dbplot.rb', line 77 def prompt @string.nil? ? 'dbplot> ' : ' -> ' end |
#template_file ⇒ Object
31 32 33 |
# File 'lib/dbplot.rb', line 31 def template_file settings[:template_file] || File.instance_eval {(join(dirname(__FILE__), 'dbplot', 'template.r.erb'))} end |