readlines 1.6 → 1.7
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/README.md +21 -98
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '01780b8ba53d712f49e869f05f707205cd2cc6206fe004a05c89b6adba755f8e'
|
4
|
+
data.tar.gz: 9af6c1d19859490a0727bc0e4e7a4e51810f0acc8d49c003ebdb7dc29b44fc41
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 05b2d6972fcd9f373d730d37678c0ab726fc9d8e3a07c37d1b9864832b3d6657bf5ceb46a786ea24de0c7e67904861b559d32ae8b3ff163af9ad96319a0c7564
|
7
|
+
data.tar.gz: 637d2e9a9dca27799fa10504ce4c570095e6e773e07c9c3d90388f747ebc313650b8f1b8ac74c093d351e5e64228d0e06c13a44f9fc38dc2f8d4337e6e7a9631
|
data/README.md
CHANGED
@@ -52,19 +52,31 @@ Run `bundle install` to install the library and its dependencies.
|
|
52
52
|
Start by requiring `readlines` in your Ruby script:
|
53
53
|
|
54
54
|
```ruby
|
55
|
-
require 'readlines'
|
55
|
+
require 'readlines/read'
|
56
56
|
```
|
57
57
|
|
58
|
-
Create an instance of the `
|
58
|
+
Create an instance of the `Readlines::ReadDuc` class with the filename (or full path):
|
59
59
|
|
60
60
|
```ruby
|
61
61
|
file_name = 'file.txt'
|
62
|
-
read =
|
62
|
+
read = Readlines::ReadDuc.new(file_name)
|
63
63
|
```
|
64
64
|
|
65
65
|
### Examples
|
66
66
|
|
67
|
+
#### Search for a specific word and count occurrences
|
68
|
+
|
69
|
+
```ruby
|
70
|
+
# Search for the word "example" in the file
|
71
|
+
read = Readlines::ReadDuc.new('data.txt')
|
72
|
+
results = read.search_about('example', show_lines: true)
|
73
|
+
|
74
|
+
# Display the number of occurrences
|
75
|
+
puts "Number of occurrences: #{results.count}"
|
76
|
+
```
|
77
|
+
|
67
78
|
#### Basic Operations
|
79
|
+
|
68
80
|
```ruby
|
69
81
|
# Read the entire file content
|
70
82
|
content = read.read_lines
|
@@ -72,11 +84,8 @@ puts content
|
|
72
84
|
```
|
73
85
|
|
74
86
|
#### Counting Operations
|
75
|
-
```ruby
|
76
|
-
# Count lines containing a specific keyword
|
77
|
-
count = read.line_count(count: 'example')
|
78
|
-
puts count
|
79
87
|
|
88
|
+
```ruby
|
80
89
|
# Count characters in the file or a specific line
|
81
90
|
total_characters = read.character_count
|
82
91
|
puts total_characters
|
@@ -90,33 +99,8 @@ line_words = read.word_count(line_specific: 3)
|
|
90
99
|
puts line_words
|
91
100
|
```
|
92
101
|
|
93
|
-
#### Search Operations
|
94
|
-
```ruby
|
95
|
-
# Search for a specific value and show line numbers
|
96
|
-
result = read.search_about('example', show_lines: true)
|
97
|
-
puts result
|
98
|
-
|
99
|
-
# Search for multiple patterns and count occurrences
|
100
|
-
patterns = [/example/, /test/]
|
101
|
-
result = read.search_multiple_patterns(patterns)
|
102
|
-
puts result
|
103
|
-
|
104
|
-
# Check if a pattern exists
|
105
|
-
pattern_exists = read.pattern_exists?(/example/)
|
106
|
-
puts pattern_exists
|
107
|
-
|
108
|
-
# Search for a pattern within a range of lines
|
109
|
-
matched_lines = read.search_in_range(5, 10, /example/)
|
110
|
-
puts matched_lines
|
111
|
-
|
112
|
-
# Logical pattern search (AND/OR operators)
|
113
|
-
and_results = read.search_logical_patterns([/example/, /test/], 'AND')
|
114
|
-
puts and_results
|
115
|
-
or_results = read.search_logical_patterns([/example/, /test/], 'OR')
|
116
|
-
puts or_results
|
117
|
-
```
|
118
|
-
|
119
102
|
#### Replacement Operations
|
103
|
+
|
120
104
|
```ruby
|
121
105
|
# Replace specific patterns in the file
|
122
106
|
updated_content = read.replace(/example/, 'new_example')
|
@@ -137,6 +121,7 @@ puts updated_content
|
|
137
121
|
```
|
138
122
|
|
139
123
|
#### Deletion Operations
|
124
|
+
|
140
125
|
```ruby
|
141
126
|
# Delete empty lines from the file
|
142
127
|
updated_content = read.delete_empty_lines
|
@@ -157,20 +142,10 @@ puts unique_content
|
|
157
142
|
# Delete specific columns in a CSV file
|
158
143
|
updated_csv = read.delete_csv_columns([1, 3])
|
159
144
|
puts updated_csv
|
160
|
-
|
161
|
-
# Filter lines based on criteria
|
162
|
-
# Replace lines starting with "hello" with "hi"
|
163
|
-
read.filter("hello", :start, :replace, "hi")
|
164
|
-
read.filter("world", :body, :replace, "guys")
|
165
|
-
read.filter("123", :end, :replace, "456")
|
166
|
-
|
167
|
-
# Delete lines containing "unwanted_text" from start or end or anywhere using `:start` or `:end` or `:body`
|
168
|
-
read.filter("unwanted_text", :start, :delete)
|
169
|
-
read.filter("unwanted_text", :body, :delete)
|
170
|
-
read.filter("unwanted_text", :end, :delete)
|
171
145
|
```
|
172
146
|
|
173
147
|
#### File Splitting and Merging
|
148
|
+
|
174
149
|
```ruby
|
175
150
|
# Split the file into 3 parts
|
176
151
|
read.split_file(3)
|
@@ -194,6 +169,7 @@ puts merged_file_with_separator
|
|
194
169
|
```
|
195
170
|
|
196
171
|
#### Encoding and Format Conversion
|
172
|
+
|
197
173
|
```ruby
|
198
174
|
# Convert encoding
|
199
175
|
read.convert_encoding('UTF-8', 'ISO-8859-1')
|
@@ -203,60 +179,7 @@ converted_csv = read.convert_to_format('csv')
|
|
203
179
|
puts converted_csv
|
204
180
|
```
|
205
181
|
|
206
|
-
####
|
207
|
-
```ruby
|
208
|
-
# Extract specific patterns (e.g., email addresses)
|
209
|
-
patterns = [/email:\s*\S+/, /phone:\s*\S+/]
|
210
|
-
extracted_data = read.extract_patterns(patterns)
|
211
|
-
puts extracted_data
|
212
|
-
|
213
|
-
# Validate content with a set of rules
|
214
|
-
rules = [/^[A-Z]/, /\b\d{3}-\d{3}-\d{4}\b/]
|
215
|
-
is_valid = read.validate_content(rules)
|
216
|
-
puts is_valid
|
217
|
-
|
218
|
-
# Check for spelling errors using a dictionary
|
219
|
-
dictionary = ['example', 'pattern', 'file']
|
220
|
-
misspelled_words = read.check_spelling(dictionary)
|
221
|
-
puts misspelled_words
|
222
|
-
```
|
223
|
-
|
224
|
-
#### File Size and Statistics
|
225
|
-
```ruby
|
226
|
-
# Get file size in different units
|
227
|
-
file_size_bytes = read.file_size
|
228
|
-
puts file_size_bytes
|
229
|
-
file_size_kb = read.file_size(unit: :kilobytes)
|
230
|
-
puts file_size_kb
|
231
|
-
file_size_mb = read.file_size(unit: :megabytes)
|
232
|
-
puts file_size_mb
|
233
|
-
file_size_gb = read.file_size(unit: :gigabytes)
|
234
|
-
puts file_size_gb
|
235
|
-
|
236
|
-
# Get statistics about the file
|
237
|
-
file_stats = read.file_statistics
|
238
|
-
puts file_stats
|
239
|
-
```
|
240
|
-
|
241
|
-
#### Encryption and Decryption
|
242
|
-
```ruby
|
243
|
-
# Encrypt content using a key
|
244
|
-
encrypted_content = read.encrypt_content(5)
|
245
|
-
puts encrypted_content
|
246
|
-
|
247
|
-
# Decrypt the content using the same key
|
248
|
-
decrypted_content = read.decrypt_content(5, '/path/to/encrypted_file.txt')
|
249
|
-
puts decrypted_content
|
250
|
-
```
|
251
|
-
|
252
|
-
#### Reverse and Additional Operations
|
253
|
-
```ruby
|
254
|
-
# Reverse the order of file contents
|
255
|
-
reversed_content = read.reverse_content
|
256
|
-
puts reversed_content
|
257
|
-
```
|
258
|
-
|
259
|
-
## Error Handling
|
182
|
+
#### Error Handling
|
260
183
|
|
261
184
|
The Readlines library provides custom error classes for handling specific exceptions:
|
262
185
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: readlines
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '1.
|
4
|
+
version: '1.7'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Maven
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2025-01-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|
@@ -84,7 +84,7 @@ description: Readlines is a Ruby library offering advanced tools for reading, wr
|
|
84
84
|
and manipulating text files. It supports searching, replacing, sorting, splitting,
|
85
85
|
merging, handling CSVs, encryption, and more. Perfect for developers needing efficient
|
86
86
|
and complex file operations.
|
87
|
-
email:
|
87
|
+
email:
|
88
88
|
executables: []
|
89
89
|
extensions: []
|
90
90
|
extra_rdoc_files: []
|
@@ -112,7 +112,7 @@ homepage: https://github.com/Abo5/readlines
|
|
112
112
|
licenses:
|
113
113
|
- MIT
|
114
114
|
metadata: {}
|
115
|
-
post_install_message:
|
115
|
+
post_install_message:
|
116
116
|
rdoc_options: []
|
117
117
|
require_paths:
|
118
118
|
- lib
|
@@ -128,7 +128,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
128
128
|
version: '0'
|
129
129
|
requirements: []
|
130
130
|
rubygems_version: 3.3.3
|
131
|
-
signing_key:
|
131
|
+
signing_key:
|
132
132
|
specification_version: 4
|
133
133
|
summary: A Ruby library for advanced text file manipulation and processing.
|
134
134
|
test_files: []
|