Class: GeoPattern::GeoPatternTask

Inherits:
RakeTask
  • Object
show all
Defined in:
lib/geo_pattern/geo_pattern_task.rb

Overview

GeoPatternTask

See Also:

  • Rakefile

Instance Attribute Summary collapse

Attributes inherited from RakeTask

#description, #name, #verbose, #verbose (true)

Instance Method Summary collapse

Methods inherited from RakeTask

#include, #instance_binding

Constructor Details

#initialize(opts = {}) ⇒ GeoPatternTask

Create a new geo pattern task

Parameters:

  • data (Hash)

    The data which should be used to generate patterns

  • allowed_patterns (Array)

    The allowed_patterns

Raises:

  • (ArgumentError)

See Also:



29
30
31
32
33
34
35
36
# File 'lib/geo_pattern/geo_pattern_task.rb', line 29

def initialize(opts = {})
  super

  raise ArgumentError, :data if @options[:data].nil?

  @data = @options[:data]
  @allowed_patterns = @options[:allowed_patterns]
end

Instance Attribute Details

#allowed_patternsObject (readonly)

Returns the value of attribute allowed_patterns.



17
18
19
# File 'lib/geo_pattern/geo_pattern_task.rb', line 17

def allowed_patterns
  @allowed_patterns
end

#dataObject (readonly)

Returns the value of attribute data.



13
14
15
# File 'lib/geo_pattern/geo_pattern_task.rb', line 13

def data
  @data
end

Instance Method Details

#run_task(_verbose) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/geo_pattern/geo_pattern_task.rb', line 39

def run_task(_verbose)
  data.each do |path, string|
    opts = {}
    path = File.expand_path(path)

    if string.is_a?(Hash)
      input = string[:input]
      opts[:patterns] = string[:patterns] if string.key? :patterns
      opts[:color] = string[:color] if string.key? :color
      opts[:base_color] = string[:base_color] if string.key? :base_color
    else
      raise "Invalid data structure for Rake Task"
    end

    pattern = GeoPattern.generate(input, opts)

    logger.info "Creating pattern at \"#{path}\"."
    FileUtils.mkdir_p File.dirname(path)
    File.write(path, pattern.to_svg)
  end
end