class DudeGl
Public Class Methods
new(params_list, opts = {})
click to toggle source
# File lib/dudegl.rb, line 6 def initialize(params_list, opts = {}) opts.key?(:dudes_per_row_max) ? dudes_per_row_max = opts[:dudes_per_row_max] : dudes_per_row_max = nil opts.key?(:renamed) ? @renamed = opts[:renamed] : @renamed = nil if opts.key?(:diff) && opts[:diff] == true @params_list = DiffParams.call(params_list, @renamed) else @params_list = params_list end @dudes = [] @params_list = @params_list.flatten @locations = DudesLocation.new(@params_list, dudes_per_row_max) build_dudes end
Public Instance Methods
render()
click to toggle source
# File lib/dudegl.rb, line 23 def render @svg = Render.new(@dudes.flatten, width = @locations.canvas_size_x, height = @locations.canvas_size_y) end
save(file_name)
click to toggle source
# File lib/dudegl.rb, line 29 def save(file_name) File.open("images/#{file_name}.svg", 'w') { |file| file.write(@svg.contents) } end
save_to_string()
click to toggle source
# File lib/dudegl.rb, line 33 def save_to_string @svg.contents end
Private Instance Methods
build_dude(params, index)
click to toggle source
# File lib/dudegl.rb, line 43 def build_dude(params, index) params = params.first if params.class == Array body = Body.new(params[:name], offsets = @locations.offsets[index], @renamed) body.changed? ? body_color = body.color : body_color = nil # draw all methods as arms, keep legs for something else... arms = Arms.new(params, body, body_color: body_color).limbs arms_draw_params = arms.map { |arm| arm.draw_data } legs_draw_params = [] (body.draw_data + arms_draw_params + legs_draw_params).flatten end
build_dudes()
click to toggle source
# File lib/dudegl.rb, line 39 def build_dudes @params_list.each_with_index { |params, index| @dudes << build_dude(params, index) } end