Sha256: 9f62dfb6812f81cbf5febc91fbedf8d8c418369d861d82f3c9fed694dce5d170

Contents?: true

Size: 522 Bytes

Versions: 1

Compression:

Stored size: 522 Bytes

Contents

require 'wlog/commands/commandable'
require 'wlog/domain/log_entry'

module Wlog
# Command that replaces a string pattern found in an entry, with another string
# @author Simon Symeonidis
class ReplacePattern < Commandable
  def initialize(id, oldpat, newpat)
    @id, @oldpat, @newpat = id, oldpat, newpat
  end

  def execute
    log_entry = LogEntry.find(@id)
    log_entry.description = log_entry.description.gsub(/#{@oldpat}/, @newpat)
    log_entry.save
  rescue ActiveRecord::RecordNotFound
    false
  end
end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
wlog-1.2.2 lib/wlog/commands/replace_pattern.rb