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

See Also:



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

def initialize(opts = {})
  super

  fail 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.



15
16
17
# File 'lib/geo_pattern/geo_pattern_task.rb', line 15

def allowed_patterns
  @allowed_patterns
end

#dataObject (readonly)

Returns the value of attribute data.



11
12
13
# File 'lib/geo_pattern/geo_pattern_task.rb', line 11

def data
  @data
end

Instance Method Details

#run_task(_verbose) ⇒ Object



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

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
      fail '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