Class: Rubicus::Layers::Prefab
- Defined in:
- lib/rubicus/layers/prefab.rb
Instance Method Summary collapse
- #draw(image_type = "png", options = {}) ⇒ Object
-
#initialize(options = {}) ⇒ Prefab
constructor
A new instance of Prefab.
Constructor Details
#initialize(options = {}) ⇒ Prefab
Returns a new instance of Prefab.
3 4 5 6 7 8 |
# File 'lib/rubicus/layers/prefab.rb', line 3 def initialize( = {}) @type = .delete(:prefab) @data = .delete(:data) = [:delim] ||= :comma end |
Instance Method Details
#draw(image_type = "png", options = {}) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/rubicus/layers/prefab.rb', line 10 def draw(image_type = "png", = {}) [image_type] = nil if image_type [:prefab] ||= @type if @data data = if @data[0].kind_of? Array @data.map {|row| row.join(delimiter_for_delim([:delim])) }.join("\n") else @data.join(",") end else data = nil end = .map { |key, option| "-#{key} #{convert_options(option)}" }.join(" ") = .map { |key, option| "#{key}=\"#{convert_options(option)}\"" }.join(" ") io = IO.popen("ploticus #{@data ? "data=stdin" : ""} #{ploticus_options} #{prefab_options}", "w+") if @data io.write data io.close_write end img = io.read io.close img end |