Class: SketchWriter

Inherits:
Object
  • Object
show all
Defined in:
lib/jruby_art/creators/sketch_writer.rb

Overview

The file writer can write a sketch when given instance of Sketch type

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, args) ⇒ SketchWriter

Returns a new instance of SketchWriter.



37
38
39
40
41
42
# File 'lib/jruby_art/creators/sketch_writer.rb', line 37

def initialize(path, args)
  @param = SketchParameters.new(name: path, args: args)
  @file = format(
    '%<dir>s/%<file>s.rb', dir: File.dirname(path), file: path
  )
end

Instance Attribute Details

#fileObject (readonly)

Returns the value of attribute file.



35
36
37
# File 'lib/jruby_art/creators/sketch_writer.rb', line 35

def file
  @file
end

#paramObject (readonly)

Returns the value of attribute param.



35
36
37
# File 'lib/jruby_art/creators/sketch_writer.rb', line 35

def param
  @param
end

Instance Method Details

#writeObject



44
45
46
47
# File 'lib/jruby_art/creators/sketch_writer.rb', line 44

def write
  sketch = SketchFactory.create(param)
  File.open(file, 'w+') { |f| f.write sketch.join("\n") }
end