class Rupat
Rupat
¶ ↑
Introduction¶ ↑
{Rupat} is a Ruby Patching utility. It can be used to patch files or for extracting information from files.
{Rupat} includes:
- {RupatMod}
-
File content manipulation methods.
- {Rupat}
-
Class methods for
Rupat
script creation. Rupat
command-
Shell command for creating
Rupat
patch files.
Typical {Rupat} script opens a file for editing, uses Regexp searches to find the file position(s) to change, and adds/replaces the content. File positions can be referred also line numbers.
Rupat
command can be used to create a patch script from diff output. The generated script includes {RupatMod} commands which implement the transformation.
{Rupat} includes lines of the file in a line Array. {Rupat} keeps track of the current line. Many editing commands use the current line to specify the context for editing.
{Rupat} has two parts: {Rupat} class and {RupatMod}. {Rupat} class is a front end class to create {Rupat} instance for editing. {Rupat} includes {RupatMod}. {RupatMod} can be used for other user classes that benefit from lines editing.
The basic flow is:
- open file
-
Source file can be opened in multiple editing modes.
- line manipulation
-
Search/jump to lines, extract and edit content (See: {RupatMod} for all access/editing methods).
- save file
-
Save the editing results to the source file or to a newly created file.
Rupat
class¶ ↑
{Rupat} is a class that provides the default entry point to the {RupatMod} module.
The user can modify, duplicate, or just read file(s).
- update
-
Perform content update for a file, but without any backups.
- edit
-
Inplace editing with possibility to backup the original.
- open
-
Open file in read-only mode. Possibility to save the changes later exist.
- create
-
A named file is to be created from source file.
Example usage:¶ ↑
# Open file for reading. r = Rupat.update( "report.txt" ) # Find line. r.find /cpp/ # Collect some lines. line = r.line data = 4.times.collect do |i| r.get( line + i ) end # Duplicate the lines collected. insertMany( data ) # Save changes. r.close
Rupat
command¶ ↑
Rupat
command is a simple shell command using {Rupat}. Main purpose is to execute Rupat
programs. It can also be used to generate a {Rupat} patch from files with different content. When applied, the patch transforms file1 to file2.
Constants
- VERSION
Public Class Methods
Create new file based on old file.
@param orgFile [String,File] Source file. @param newFile [String] Destination file.
# File lib/rupat.rb, line 893 def Rupat.create( orgFile, newFile ) r = Rupat.new r.create( orgFile, newFile ) r end
Edit existing file and by default make backup.
@param file [String,File] Source file. @param backup [Boolean] Create backup from the source (original)
file.
# File lib/rupat.rb, line 882 def Rupat.edit( file, backup = true ) r = Rupat.new r.edit( file, backup ) r end
Use set of lines for editing.
@param lines [Array<String>] Lines to edit.
# File lib/rupat.rb, line 903 def Rupat.lines( lines ) r = Rupat.new r.use( lines ) r end
Open existing file for reading.
@param file [String,File] Source file.
# File lib/rupat.rb, line 862 def Rupat.open( file ) r = Rupat.new r.open( file ) r end
Open existing file for reading.
@param file [String,File] Source file.
# File lib/rupat.rb, line 872 def Rupat.readonly( file ) Rupat.open( file ) end
Edit existing file inplace without backups.
@param file [String,File] Source file.
# File lib/rupat.rb, line 854 def Rupat.update( file ) Rupat.edit( file, false ) end
# File lib/version.rb, line 3 def Rupat.version Rupat::VERSION end
Public Instance Methods
Use short aliases from {RupatAlias} module.
# File lib/rupat.rb, line 911 def useAlias Rupat.send( :include, RupatAlias ) self end