Class: TrianglePattern::TriangleTask
- Defined in:
- lib/triangle_pattern/triangle_task.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
Attributes inherited from RakeTask
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ TriangleTask
constructor
A new instance of TriangleTask.
- #run_task(_verbose) ⇒ Object
Methods inherited from RakeTask
Constructor Details
#initialize(opts = {}) ⇒ TriangleTask
Returns a new instance of TriangleTask.
7 8 9 10 11 |
# File 'lib/triangle_pattern/triangle_task.rb', line 7 def initialize(opts = {}) super raise ArgumentError, :data if @options[:data].nil? @data = @options[:data] end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
6 7 8 |
# File 'lib/triangle_pattern/triangle_task.rb', line 6 def data @data end |
Instance Method Details
#run_task(_verbose) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/triangle_pattern/triangle_task.rb', line 13 def run_task(_verbose) data.each do |path, string| opts = {} path = File.(path) if string.is_a?(Hash) opts[:colors] = string[:colors] if string.key? :colors opts[:width] = string[:width] if string.key? :width opts[:height] = string[:height] if string.key? :height opts[:cell_size] = string[:cell_size] if string.key? :cell_size opts[:seed] = string[:seed] if string.key? :seed opts[:variance] = string[:variance] if string.key? :variance else raise 'Invalid data structure for Rake Task' end pattern = TrianglePattern.generate(opts) logger.info "Creating pattern at \"#{path}\"." FileUtils.mkdir_p File.dirname(path) File.write(path, pattern.to_svg) end end |