patman 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.rdoc +2 -0
- data/README.rdoc +106 -7
- data/doc/Patman/PatmanError.html +1 -1
- data/doc/Patman/PatmanFileError.html +1 -1
- data/doc/Patman/PatmanSearchError.html +1 -1
- data/doc/Patman.html +300 -376
- data/doc/_index.html +1 -1
- data/doc/file.CHANGELOG.html +5 -2
- data/doc/file.README.html +109 -8
- data/doc/index.html +109 -8
- data/doc/top-level-namespace.html +1 -1
- data/lib/patman.rb +0 -81
- data/lib/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b68fa454daf8ce04aeb42aabc60f2de3021db888
|
4
|
+
data.tar.gz: '068b4d5320b270d4bc82cd73a1e023adfde8b709'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cc7654dc6ec333b5a95af55035c62318e0239068dcd67084e72545939fb858a78eccaa6e3e1d816e5a3122a13fda86e05055150f679169225fb2c350bf8663ca
|
7
|
+
data.tar.gz: 0d95179441b056dbe816802d44873cb56ad9c6cac734f391dd9cb14d059307beed47d86ff3d7ea355ebf764bcc12a68eef4e9e89a2325902a5396fb4da9c1fb8
|
data/CHANGELOG.rdoc
CHANGED
data/README.rdoc
CHANGED
@@ -1,14 +1,113 @@
|
|
1
1
|
= Patman
|
2
2
|
|
3
|
-
|
3
|
+
{Patman} (Patch Manipulator) is a library for text file patching. It
|
4
|
+
can also be used to extract information from files.
|
4
5
|
|
5
|
-
|
6
|
-
just extract information from files.
|
6
|
+
== Documentation
|
7
7
|
|
8
|
+
Here is a brief overview of {Patman}. Please refer to API
|
9
|
+
documentation for complete view. Also refer to tests for multiple ways
|
10
|
+
of how to use {Patman}.
|
8
11
|
|
9
|
-
|
12
|
+
Typical {Patman} script opens files for editing. File is read into the
|
13
|
+
library as content line by line. User finds the place for editing
|
14
|
+
either with Regexp searches or with direct line numbers. The file
|
15
|
+
content is edited by adding, removing, or replacing lines. When all
|
16
|
+
edits are done, the updated file content is written to disk.
|
17
|
+
|
18
|
+
r = Patman.read( "edit_me.txt" )
|
19
|
+
r.line 10
|
20
|
+
r.delete
|
21
|
+
r.write
|
22
|
+
|
23
|
+
All editing commands refer to the "current position". Current position
|
24
|
+
is returned by "line" method. Positions refer to lines that have
|
25
|
+
content. Line numbers start from 1. If user wants append to the end of
|
26
|
+
file, then user should jump to last line, with "lastline" method, and
|
27
|
+
then issue "append". It is also possible to jump to arbitrary lines,
|
28
|
+
{Patman} does not prevent this. The line positions are just used as an
|
29
|
+
index to Array. For example negative line number will refer from end
|
30
|
+
towards beginning in content.
|
31
|
+
|
32
|
+
Position can be explicitly changed with "line", "step", "firstline",
|
33
|
+
or "lastline" methods (commands). "find" changes position if the
|
34
|
+
pattern is found in selected direction. "append" changes position
|
35
|
+
implicitly with every call.
|
36
|
+
|
37
|
+
curline = r.line
|
38
|
+
if curline > 5
|
39
|
+
r.step -2
|
40
|
+
else
|
41
|
+
r.line 10
|
42
|
+
|
43
|
+
Current line content is returned by "get" and it can be set with
|
44
|
+
"set" method. Current line content can be replaced with "sub".
|
45
|
+
|
46
|
+
r.set( r.get + "..." )
|
47
|
+
|
48
|
+
{Patman} includes many query commands: line, lines, [], get, find,
|
49
|
+
get_range, get_for. They all return the queried item. All other
|
50
|
+
methods return {Patman} object itself, hence many {Patman} methods
|
51
|
+
can be "chained".
|
52
|
+
|
53
|
+
Patman.read( "edit_me.txt" ).line( 2 ).delete.write
|
54
|
+
|
55
|
+
Block commands perform commands over a range of lines. Block commands
|
56
|
+
are: do_all, do_range, and do_for. These retain the original position,
|
57
|
+
but the final position is stored (actually one after) and it can be
|
58
|
+
activated by calling "blockline" method, i.e. {Patman} jumps to that
|
59
|
+
line.
|
60
|
+
|
61
|
+
Block commands take a pre-defined number of lines to process. Note
|
62
|
+
that, if user deletes lines in block action, the outcome is most
|
63
|
+
likely not what the user expects.
|
64
|
+
|
65
|
+
Mark feature can be used if user wants to return back to original
|
66
|
+
position after changes. Mark features includes a "default mark" and
|
67
|
+
"named marks".
|
68
|
+
|
69
|
+
r.mark :origin
|
70
|
+
r.step 10
|
71
|
+
r.delete
|
72
|
+
r.unmark :origin
|
73
|
+
|
74
|
+
For debugging purposes it is good to see line content. "view" and
|
75
|
+
"view_ln" can be used to view line content either without or with
|
76
|
+
line numbers respectively.
|
77
|
+
|
78
|
+
No changes are stored to disk unless "write" is called. If user want
|
79
|
+
to create a "backup" of the edited file, the "copy" method can be used
|
80
|
+
before any editing commands have been applied.
|
81
|
+
|
82
|
+
|
83
|
+
== Example session
|
84
|
+
|
85
|
+
# Open file for reading.
|
86
|
+
r = Patman.read( "report.txt" )
|
87
|
+
|
88
|
+
# Backup file and find next line with "error", i.e. method chaining.
|
89
|
+
r.copy( "report.txt.org" ).find( /error/ )
|
90
|
+
|
91
|
+
# Collect some lines.
|
92
|
+
data = 4.times.collect do |i|
|
93
|
+
r.ref( r.line + i )
|
94
|
+
end
|
95
|
+
|
96
|
+
# Duplicate the lines collected.
|
97
|
+
r.insert( data )
|
98
|
+
|
99
|
+
# Move to line 9.
|
100
|
+
r.line 9
|
101
|
+
|
102
|
+
# Append " Hello" to the end of current line.
|
103
|
+
r.set( r.get + " Hello" )
|
104
|
+
|
105
|
+
# Save changes.
|
106
|
+
r.write
|
107
|
+
|
108
|
+
|
109
|
+
== Testing
|
10
110
|
|
11
|
-
|
111
|
+
Tests are executed with:
|
12
112
|
|
13
|
-
|
14
|
-
{Patman}.
|
113
|
+
rake test
|
data/doc/Patman/PatmanError.html
CHANGED
@@ -129,7 +129,7 @@
|
|
129
129
|
</div>
|
130
130
|
|
131
131
|
<div id="footer">
|
132
|
-
Generated on
|
132
|
+
Generated on Tue Mar 20 20:43:44 2018 by
|
133
133
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
134
134
|
0.8.7.6 (ruby-2.3.3).
|
135
135
|
</div>
|
@@ -133,7 +133,7 @@
|
|
133
133
|
</div>
|
134
134
|
|
135
135
|
<div id="footer">
|
136
|
-
Generated on
|
136
|
+
Generated on Tue Mar 20 20:43:44 2018 by
|
137
137
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
138
138
|
0.8.7.6 (ruby-2.3.3).
|
139
139
|
</div>
|
@@ -133,7 +133,7 @@
|
|
133
133
|
</div>
|
134
134
|
|
135
135
|
<div id="footer">
|
136
|
-
Generated on
|
136
|
+
Generated on Tue Mar 20 20:43:44 2018 by
|
137
137
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
138
138
|
0.8.7.6 (ruby-2.3.3).
|
139
139
|
</div>
|