Sha256: 68d9fd12c1bfe562968ba51051597bd5e29769427d141deb178e5bfffc63df30

Contents?: true

Size: 990 Bytes

Versions: 8

Compression:

Stored size: 990 Bytes

Contents

<% redirect do |target| %># <%= const.name %>::manifest <replace with manifest summary>
# <replace with command line description>

# <%= const.const_name %> Documentation
# This example FileTask counts the specified letters
# in a source file and writes the counts to a target
# file as YAML.
#
class <%= const.const_name %> < Tap::FileTask

  # <config file documentation>
  config :letters, ['a','e','i','o','u'], &c.array  # a list of letters to count

  def process(source, target)

    # prepare ensures the parent directory for target
    # exists and, if necessary, backs up the existing
    # target file (which is restored on error)
    prepare(target) 

    # now perform the task...
    str = File.read(source)
    letter_count = letters.collect do |letter|
      str.count(letter)
    end

    File.open(target, "wb") do |file|
      file << letter_count.to_yaml
    end

    target
  end
end <% module_nest(const.nesting, '  ') { target } end %>

Version data entries

8 entries across 8 versions & 2 rubygems

Version Path
bahuvrihi-tap-0.10.0 lib/tap/generator/generators/file_task/templates/task.erb
bahuvrihi-tap-0.10.1 lib/tap/generator/generators/file_task/templates/task.erb
bahuvrihi-tap-0.10.2 lib/tap/generator/generators/file_task/templates/task.erb
bahuvrihi-tap-0.10.3 lib/tap/generator/generators/file_task/templates/task.erb
bahuvrihi-tap-0.10.4 lib/tap/generator/generators/file_task/templates/task.erb
bahuvrihi-tap-0.10.5 lib/tap/generator/generators/file_task/templates/task.erb
tap-0.10.1 lib/tap/generator/generators/file_task/templates/task.erb
tap-0.10.0 lib/tap/generator/generators/file_task/templates/task.erb