readlines 1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.github/workflows/gem-push.yml +45 -0
- data/.gitignore +46 -0
- data/.rspec +0 -0
- data/CHANGELOG.md +36 -0
- data/CODE_OF_CONDUCT.md +0 -0
- data/Gemfile +5 -0
- data/Gemfile.lock +30 -0
- data/LICENSE +21 -0
- data/README.md +349 -0
- data/Rakefile +9 -0
- data/examples/example1.rb +13 -0
- data/examples/example10.rb +13 -0
- data/examples/example11.rb +13 -0
- data/examples/example12.rb +13 -0
- data/examples/example13.rb +13 -0
- data/examples/example14.rb +13 -0
- data/examples/example15.rb +13 -0
- data/examples/example16.rb +13 -0
- data/examples/example17.rb +13 -0
- data/examples/example18.rb +13 -0
- data/examples/example19.rb +13 -0
- data/examples/example2.rb +13 -0
- data/examples/example20.rb +13 -0
- data/examples/example21.rb +13 -0
- data/examples/example22.rb +13 -0
- data/examples/example23.rb +13 -0
- data/examples/example24.rb +13 -0
- data/examples/example25.rb +13 -0
- data/examples/example26.rb +13 -0
- data/examples/example27.rb +13 -0
- data/examples/example28.rb +13 -0
- data/examples/example29.rb +13 -0
- data/examples/example3.rb +13 -0
- data/examples/example30.rb +13 -0
- data/examples/example31.rb +13 -0
- data/examples/example32.rb +13 -0
- data/examples/example33.rb +13 -0
- data/examples/example34.rb +13 -0
- data/examples/example35.rb +13 -0
- data/examples/example36.rb +13 -0
- data/examples/example37.rb +13 -0
- data/examples/example38.rb +13 -0
- data/examples/example4.rb +13 -0
- data/examples/example5.rb +13 -0
- data/examples/example6.rb +13 -0
- data/examples/example7.rb +13 -0
- data/examples/example8.rb +13 -0
- data/examples/example9.rb +13 -0
- data/lib/read.rb +9 -0
- data/lib/readlines/read.rb +263 -0
- data/lib/readlines/readlines/check.rb +16 -0
- data/lib/readlines/readlines/content.rb +45 -0
- data/lib/readlines/readlines/convert.rb +43 -0
- data/lib/readlines/readlines/count.rb +58 -0
- data/lib/readlines/readlines/delete.rb +89 -0
- data/lib/readlines/readlines/error.rb +13 -0
- data/lib/readlines/readlines/file.rb +20 -0
- data/lib/readlines/readlines/info.rb +48 -0
- data/lib/readlines/readlines/merge.rb +38 -0
- data/lib/readlines/readlines/pattern.rb +22 -0
- data/lib/readlines/readlines/replace.rb +50 -0
- data/lib/readlines/readlines/search.rb +62 -0
- data/lib/readlines/readlines/sort.rb +18 -0
- data/lib/readlines/readlines/split.rb +79 -0
- data/lib/readlines/readlines/version.rb +7 -0
- data/readlines.gemspec +25 -0
- metadata +182 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: fc88452fd69e2ffcc11e0c8856934df4b0e451696a1a32dbd432b2766eb03d9c
|
4
|
+
data.tar.gz: 67d64d4bca0d815e8f8248044b4eb79df246dd8542d1623f9978c34aacb79996
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 186747fc51905ddbd85eac0800694850c94de14408bf885e5c61bf62096aeee991aec0056d6d03106d9a42bdfc79767f8885106a1364296142ae2d8940548b83
|
7
|
+
data.tar.gz: a69d75cc7000dc29802f86ca2b6dd9cb90070f3183eb037483442d6414452ab91d8052409223ad86daf76baedff538e15b0ad22681cefb4b80985050e691ac2f
|
@@ -0,0 +1,45 @@
|
|
1
|
+
name: Ruby Gem
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches: [ "main" ]
|
6
|
+
pull_request:
|
7
|
+
branches: [ "main" ]
|
8
|
+
|
9
|
+
jobs:
|
10
|
+
build:
|
11
|
+
name: Build + Publish
|
12
|
+
runs-on: ubuntu-latest
|
13
|
+
permissions:
|
14
|
+
contents: read
|
15
|
+
packages: write
|
16
|
+
|
17
|
+
steps:
|
18
|
+
- uses: actions/checkout@v4
|
19
|
+
|
20
|
+
- name: Set up Ruby
|
21
|
+
uses: ruby/setup-ruby@v1
|
22
|
+
with:
|
23
|
+
ruby-version: 3.1.0
|
24
|
+
|
25
|
+
|
26
|
+
|
27
|
+
- name: Check Ruby version
|
28
|
+
run: ruby --version
|
29
|
+
|
30
|
+
- name: Check gem version
|
31
|
+
run: gem --version
|
32
|
+
|
33
|
+
- name: Install Bundler with verbose output
|
34
|
+
run: gem install bundler --no-document --verbose
|
35
|
+
|
36
|
+
- name: Verify Bundler installation
|
37
|
+
run: bundler --version
|
38
|
+
|
39
|
+
- name: Build the gem
|
40
|
+
run: gem build *.gemspec
|
41
|
+
|
42
|
+
- name: Push to RubyGems
|
43
|
+
run: gem push *.gem
|
44
|
+
env:
|
45
|
+
GEM_HOST_API_KEY: "${{secrets.RUBYGEMS_AUTH_TOKEN}}"
|
data/.gitignore
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
# Ignore Ruby and Rails specific files
|
2
|
+
*.rbc
|
3
|
+
*.log
|
4
|
+
*.gem
|
5
|
+
*.rdoc
|
6
|
+
db/*.sqlite3
|
7
|
+
db/*.sqlite3-journal
|
8
|
+
tmp/
|
9
|
+
coverage/
|
10
|
+
|
11
|
+
# Ignore all logfiles and tempfiles.
|
12
|
+
/log/*
|
13
|
+
/tmp/*
|
14
|
+
!/log/.keep
|
15
|
+
!/tmp/.keep
|
16
|
+
|
17
|
+
# Ignore files related to version control systems
|
18
|
+
.git/
|
19
|
+
.svn/
|
20
|
+
.hg/
|
21
|
+
|
22
|
+
# Ignore bundler config and installed gems
|
23
|
+
/.bundle
|
24
|
+
/vendor/bundle
|
25
|
+
|
26
|
+
# Ignore specific environment configuration files
|
27
|
+
.env
|
28
|
+
.secret
|
29
|
+
|
30
|
+
# Ignore IDE-specific files (e.g., for VSCode, RubyMine, SublimeText)
|
31
|
+
.idea/
|
32
|
+
*.swp
|
33
|
+
*.swo
|
34
|
+
*.sublime-workspace
|
35
|
+
*.sublime-project
|
36
|
+
.vscode/
|
37
|
+
|
38
|
+
# Other common ignore patterns
|
39
|
+
.DS_Store
|
40
|
+
Thumbs.db
|
41
|
+
test_file-copy.json
|
42
|
+
read.rb
|
43
|
+
proxy.txt
|
44
|
+
main.rb
|
45
|
+
info_spec.rb
|
46
|
+
create.rb
|
data/.rspec
ADDED
File without changes
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
- Read the entire file content or specific parts of it.
|
2
|
+
- Search for specific values in the file and display matching line numbers.
|
3
|
+
- Count the number of lines in the file based on a keyword or delimiter.
|
4
|
+
- Replace specific patterns in the file with replacement text.
|
5
|
+
- Remove empty lines from the file.
|
6
|
+
- Sort the lines of the file alphabetically.
|
7
|
+
- Split the file into a specified number of parts.
|
8
|
+
- Merge multiple files into a single file.
|
9
|
+
- Convert the encoding of the file from one encoding to another.
|
10
|
+
- Replace special characters in the file with a replacement string.
|
11
|
+
- Remove unwanted characters from the file.
|
12
|
+
- Split the file by a specified size.
|
13
|
+
- Convert the file to a specified format (txt, csv, json).
|
14
|
+
- Search for multiple patterns in the file and count occurrences of each pattern.
|
15
|
+
- Replace multiple patterns in the file in a single operation.
|
16
|
+
- Split the file based on a specified delimiter.
|
17
|
+
- Merge multiple files into a single file with a specified separator between each file's content.
|
18
|
+
- Check if a specific pattern exists in the file.
|
19
|
+
- Delete specific lines from the file with the option to remove resulting empty lines.
|
20
|
+
- Reverse the order of the file contents.
|
21
|
+
- Search for a pattern within a specified range of lines.
|
22
|
+
- Count the number of characters in the file or in a specific line.
|
23
|
+
- Count the number of words in the file or in a specific line.
|
24
|
+
- Extract specific patterns from the file.
|
25
|
+
- Convert the file contents into an array of lines.
|
26
|
+
- Validate the file contents against a set of rules.
|
27
|
+
- Remove duplicate lines from the file.
|
28
|
+
- Get statistics about the file (number of lines, characters, words).
|
29
|
+
- Search for logical patterns in the file using AND and OR operators.
|
30
|
+
- Split the file based on a specified pattern.
|
31
|
+
- Delete specific columns from a CSV file.
|
32
|
+
- Replace a specific value in a CSV column.
|
33
|
+
- Check for spelling errors in the file using a dictionary.
|
34
|
+
- Encrypt the file contents using a key.
|
35
|
+
- Decrypt the encrypted file contents using a key.
|
36
|
+
- Get the file size in different units (bytes, kilobytes, megabytes, gigabytes).
|
data/CODE_OF_CONDUCT.md
ADDED
File without changes
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
GEM
|
2
|
+
remote: https://rubygems.org/
|
3
|
+
specs:
|
4
|
+
diff-lcs (1.5.1)
|
5
|
+
fileutils (1.7.2)
|
6
|
+
json (2.7.2)
|
7
|
+
rspec (3.13.0)
|
8
|
+
rspec-core (~> 3.13.0)
|
9
|
+
rspec-expectations (~> 3.13.0)
|
10
|
+
rspec-mocks (~> 3.13.0)
|
11
|
+
rspec-core (3.13.0)
|
12
|
+
rspec-support (~> 3.13.0)
|
13
|
+
rspec-expectations (3.13.1)
|
14
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
15
|
+
rspec-support (~> 3.13.0)
|
16
|
+
rspec-mocks (3.13.1)
|
17
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
18
|
+
rspec-support (~> 3.13.0)
|
19
|
+
rspec-support (3.13.1)
|
20
|
+
|
21
|
+
PLATFORMS
|
22
|
+
arm64-darwin-23
|
23
|
+
|
24
|
+
DEPENDENCIES
|
25
|
+
fileutils
|
26
|
+
json
|
27
|
+
rspec
|
28
|
+
|
29
|
+
BUNDLED WITH
|
30
|
+
2.5.14
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2024 MAVEN
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,349 @@
|
|
1
|
+
# Readlines Library
|
2
|
+
|
3
|
+
Readlines is a powerful and versatile Ruby library for file manipulation and processing. It provides a wide range of functionality to read, analyze, and modify the contents of text files efficiently.
|
4
|
+
|
5
|
+
## Features
|
6
|
+
|
7
|
+
- Read the entire file content or specific parts of it.
|
8
|
+
- Search for specific values in the file and display matching line numbers.
|
9
|
+
- Count the number of lines in the file based on a keyword or delimiter.
|
10
|
+
- Replace specific patterns in the file with replacement text.
|
11
|
+
- Remove empty lines from the file.
|
12
|
+
- Sort the lines of the file alphabetically.
|
13
|
+
- Split the file into a specified number of parts.
|
14
|
+
- Merge multiple files into a single file.
|
15
|
+
- Convert the encoding of the file from one encoding to another.
|
16
|
+
- Replace special characters in the file with a replacement string.
|
17
|
+
- Remove unwanted characters from the file.
|
18
|
+
- Split the file by a specified size.
|
19
|
+
- Convert the file to a specified format (txt, csv, json).
|
20
|
+
- Search for multiple patterns in the file and count occurrences of each pattern.
|
21
|
+
- Replace multiple patterns in the file in a single operation.
|
22
|
+
- Split the file based on a specified delimiter.
|
23
|
+
- Merge multiple files into a single file with a specified separator between each file's content.
|
24
|
+
- Check if a specific pattern exists in the file.
|
25
|
+
- Delete specific lines from the file with the option to remove resulting empty lines.
|
26
|
+
- Reverse the order of the file contents.
|
27
|
+
- Search for a pattern within a specified range of lines.
|
28
|
+
- Count the number of characters in the file or in a specific line.
|
29
|
+
- Count the number of words in the file or in a specific line.
|
30
|
+
- Extract specific patterns from the file.
|
31
|
+
- Convert the file contents into an array of lines.
|
32
|
+
- Validate the file contents against a set of rules.
|
33
|
+
- Remove duplicate lines from the file.
|
34
|
+
- Get statistics about the file (number of lines, characters, words).
|
35
|
+
- Search for logical patterns in the file using AND and OR operators.
|
36
|
+
- Split the file based on a specified pattern.
|
37
|
+
- Delete specific columns from a CSV file.
|
38
|
+
- Replace a specific value in a CSV column.
|
39
|
+
- Check for spelling errors in the file using a dictionary.
|
40
|
+
- Encrypt the file contents using a key.
|
41
|
+
- Decrypt the encrypted file contents using a key.
|
42
|
+
- Get the file size in different units (bytes, kilobytes, megabytes, gigabytes).
|
43
|
+
|
44
|
+
## Installation
|
45
|
+
|
46
|
+
To use the Readlines library in your Ruby project, you can install it via RubyGems. Run the following command:
|
47
|
+
|
48
|
+
```
|
49
|
+
gem install readlines
|
50
|
+
```
|
51
|
+
|
52
|
+
Alternatively, you can add the following line to your project's Gemfile:
|
53
|
+
|
54
|
+
```ruby
|
55
|
+
gem 'readlines'
|
56
|
+
```
|
57
|
+
|
58
|
+
Then, run `bundle install` to install the library and its dependencies.
|
59
|
+
|
60
|
+
## Usage
|
61
|
+
|
62
|
+
To start using the Readlines library, require it in your Ruby script:
|
63
|
+
|
64
|
+
```ruby
|
65
|
+
require 'readlines'
|
66
|
+
```
|
67
|
+
|
68
|
+
Create an instance of the `Read` class, providing the path to the file you want to work with:
|
69
|
+
|
70
|
+
```ruby
|
71
|
+
file_path = '/path/to/your/file.txt'
|
72
|
+
read = Read.new(file_path)
|
73
|
+
```
|
74
|
+
|
75
|
+
Now you can use the various methods provided by the library to manipulate and process the file contents. Here are some examples:
|
76
|
+
```ruby
|
77
|
+
# imagen you have file inside of it data like this and you want count all data of names how manually no you can use this method and that will count for you body 😁
|
78
|
+
# ++++++++++++++++++++++++++++++++++++
|
79
|
+
# name : 'john'
|
80
|
+
# phone : '+1 332-332-3322'
|
81
|
+
#++++++++++++++++++++++++++++++++++++
|
82
|
+
read = Read.new(file_path, count: 'name', split: '++++++++++++++++++++++++++++++++++++')
|
83
|
+
puts read.line_count
|
84
|
+
```
|
85
|
+
```ruby
|
86
|
+
# Read the entire file content
|
87
|
+
content = read.read_lines
|
88
|
+
puts content
|
89
|
+
```
|
90
|
+
```ruby
|
91
|
+
# Search for a specific value in the file and display matching line numbers
|
92
|
+
value = 'example'
|
93
|
+
result = read.search_about(value, show_lines: true)
|
94
|
+
puts result
|
95
|
+
```
|
96
|
+
```ruby
|
97
|
+
# Count the number of lines in the file based on a keyword or delimiter
|
98
|
+
keyword = 'example'
|
99
|
+
delimiter = '---'
|
100
|
+
count = read.line_count(count: keyword, split: delimiter)
|
101
|
+
puts count
|
102
|
+
```
|
103
|
+
```ruby
|
104
|
+
# Replace specific patterns in the file with replacement text
|
105
|
+
pattern = /example/
|
106
|
+
replacement = 'new_example'
|
107
|
+
updated_content = read.replace(pattern, replacement)
|
108
|
+
puts updated_content
|
109
|
+
```
|
110
|
+
```ruby
|
111
|
+
# Remove empty lines from the file
|
112
|
+
updated_content = read.remove_empty_lines
|
113
|
+
puts updated_content
|
114
|
+
```
|
115
|
+
```ruby
|
116
|
+
# Sort the lines of the file alphabetically
|
117
|
+
sorted_content = read.sort_alphabetically
|
118
|
+
puts sorted_content
|
119
|
+
```
|
120
|
+
```ruby
|
121
|
+
# Split the file into a specified number of parts
|
122
|
+
num_parts = 3
|
123
|
+
read.split_file(num_parts)
|
124
|
+
```
|
125
|
+
```ruby
|
126
|
+
# Merge multiple files into a single file
|
127
|
+
file_paths = ['/path/to/file1.txt', '/path/to/file2.txt']
|
128
|
+
merged_file = read.merge_files(file_paths)
|
129
|
+
puts merged_file
|
130
|
+
```
|
131
|
+
```ruby
|
132
|
+
# Convert the encoding of the file from one encoding to another
|
133
|
+
from_encoding = 'UTF-8'
|
134
|
+
to_encoding = 'ISO-8859-1'
|
135
|
+
read.convert_encoding(from_encoding, to_encoding)
|
136
|
+
```
|
137
|
+
```ruby
|
138
|
+
# Replace special characters in the file with a replacement string
|
139
|
+
replacement = '_'
|
140
|
+
updated_content = read.replace_special_characters(replacement)
|
141
|
+
puts updated_content
|
142
|
+
```
|
143
|
+
```ruby
|
144
|
+
# Remove unwanted characters from the file
|
145
|
+
unwanted_chars = '!@#$%^&*()'
|
146
|
+
updated_content = read.remove_unwanted_characters(unwanted_chars)
|
147
|
+
puts updated_content
|
148
|
+
```
|
149
|
+
```ruby
|
150
|
+
# Split the file by a specified size
|
151
|
+
part_size = 1024 # 1 KB
|
152
|
+
read.split_file_by_size(part_size)
|
153
|
+
```
|
154
|
+
```ruby
|
155
|
+
# Convert the file to a specified format
|
156
|
+
format = 'csv'
|
157
|
+
converted_file = read.convert_to_format(format)
|
158
|
+
puts converted_file
|
159
|
+
```
|
160
|
+
```ruby
|
161
|
+
# Search for multiple patterns in the file and count occurrences of each pattern
|
162
|
+
patterns = [/example/, /pattern/]
|
163
|
+
result = read.search_multiple_patterns(patterns)
|
164
|
+
puts result
|
165
|
+
```
|
166
|
+
```ruby
|
167
|
+
# Replace multiple patterns in the file in a single operation
|
168
|
+
pattern_replacement_hash = {/example/ => 'new_example', /pattern/ => 'new_pattern'}
|
169
|
+
updated_content = read.replace_multiple_patterns(pattern_replacement_hash)
|
170
|
+
puts updated_content
|
171
|
+
```
|
172
|
+
```ruby
|
173
|
+
# Split the file based on a specified delimiter
|
174
|
+
delimiter = '---'
|
175
|
+
read.split_by_delimiter(delimiter)
|
176
|
+
```
|
177
|
+
```ruby
|
178
|
+
# Merge multiple files into a single file with a specified separator between each file's content
|
179
|
+
file_paths = ['/path/to/file1.txt', '/path/to/file2.txt']
|
180
|
+
separator = '---'
|
181
|
+
merged_file = read.merge_files(file_paths, separator: separator)
|
182
|
+
puts merged_file
|
183
|
+
```
|
184
|
+
```ruby
|
185
|
+
# Check if a specific pattern exists in the file
|
186
|
+
pattern = /example/
|
187
|
+
exists = read.pattern_exists?(pattern)
|
188
|
+
puts exists
|
189
|
+
```
|
190
|
+
```ruby
|
191
|
+
# Delete specific lines from the file with the option to remove resulting empty lines
|
192
|
+
line_numbers = [2, 4, 6]
|
193
|
+
updated_content = read.delete_lines(line_numbers, delete_space: true)
|
194
|
+
puts updated_content
|
195
|
+
```
|
196
|
+
```ruby
|
197
|
+
# Reverse the order of the file contents
|
198
|
+
reversed_content = read.reverse_content
|
199
|
+
puts reversed_content
|
200
|
+
```
|
201
|
+
```ruby
|
202
|
+
# Search for a pattern within a specified range of lines
|
203
|
+
start_line = 5
|
204
|
+
end_line = 10
|
205
|
+
pattern = /example/
|
206
|
+
matched_lines = read.search_in_range(start_line, end_line, pattern)
|
207
|
+
puts matched_lines
|
208
|
+
```
|
209
|
+
```ruby
|
210
|
+
# Count the number of characters in the file or in a specific line
|
211
|
+
total_characters = read.character_count
|
212
|
+
puts total_characters
|
213
|
+
|
214
|
+
line_number = 3
|
215
|
+
line_characters = read.character_count(line_specific: line_number)
|
216
|
+
puts line_characters
|
217
|
+
```
|
218
|
+
```ruby
|
219
|
+
# Count the number of words in the file or in a specific line
|
220
|
+
total_words = read.word_count
|
221
|
+
puts total_words
|
222
|
+
|
223
|
+
line_number = 3
|
224
|
+
line_words = read.word_count(line_specific: line_number)
|
225
|
+
puts line_words
|
226
|
+
```
|
227
|
+
```ruby
|
228
|
+
# Extract specific patterns from the file
|
229
|
+
patterns = [/email:\s*\S+/, /phone:\s*\S+/]
|
230
|
+
extracted_data = read.extract_patterns(patterns)
|
231
|
+
puts extracted_data
|
232
|
+
```
|
233
|
+
```ruby
|
234
|
+
# Convert the file contents into an array of lines
|
235
|
+
lines_array = read.convert_to_array
|
236
|
+
puts lines_array
|
237
|
+
```
|
238
|
+
```ruby
|
239
|
+
# Validate the file contents against a set of rules
|
240
|
+
rules = [/^[A-Z]/, /\b\d{3}-\d{3}-\d{4}\b/]
|
241
|
+
is_valid = read.validate_content(rules)
|
242
|
+
puts is_valid
|
243
|
+
```
|
244
|
+
```ruby
|
245
|
+
# Remove duplicate lines from the file
|
246
|
+
unique_content = read.remove_duplicate_lines
|
247
|
+
puts unique_content
|
248
|
+
```
|
249
|
+
```ruby
|
250
|
+
# Get statistics about the file
|
251
|
+
stats = read.file_statistics
|
252
|
+
puts stats
|
253
|
+
```
|
254
|
+
```ruby
|
255
|
+
# Search for logical patterns in the file using AND and OR operators
|
256
|
+
patterns = [/example/, /pattern/]
|
257
|
+
and_matched_lines = read.search_logical_patterns(patterns, 'AND')
|
258
|
+
puts and_matched_lines
|
259
|
+
```
|
260
|
+
```ruby
|
261
|
+
or_matched_lines = read.search_logical_patterns(patterns, 'OR')
|
262
|
+
puts or_matched_lines
|
263
|
+
```
|
264
|
+
```ruby
|
265
|
+
# Split the file based on a specified pattern
|
266
|
+
pattern = /Chapter \d+:/
|
267
|
+
read.split_by_pattern(pattern)
|
268
|
+
```
|
269
|
+
```ruby
|
270
|
+
# Delete specific columns from a CSV file
|
271
|
+
column_indices = [1, 3]
|
272
|
+
updated_csv = read.delete_csv_columns(column_indices)
|
273
|
+
puts updated_csv
|
274
|
+
```
|
275
|
+
```ruby
|
276
|
+
# Replace a specific value in a CSV column
|
277
|
+
column_index = 2
|
278
|
+
old_value = 'old_value'
|
279
|
+
new_value = 'new_value'
|
280
|
+
updated_csv = read.replace_csv_value(column_index, old_value, new_value)
|
281
|
+
puts updated_csv
|
282
|
+
```
|
283
|
+
```ruby
|
284
|
+
# Check for spelling errors in the file using a dictionary
|
285
|
+
dictionary = ['example', 'pattern', 'file']
|
286
|
+
misspelled_words = read.check_spelling(dictionary)
|
287
|
+
puts misspelled_words
|
288
|
+
```
|
289
|
+
```ruby
|
290
|
+
# Encrypt the file contents using a key
|
291
|
+
key = 5
|
292
|
+
encrypted_file = read.encrypt_content(key)
|
293
|
+
puts encrypted_file
|
294
|
+
```
|
295
|
+
```ruby
|
296
|
+
# Decrypt the encrypted file contents using a key
|
297
|
+
encrypted_file_path = '/path/to/encrypted_file.txt'
|
298
|
+
decrypted_file = read.decrypt_content(key, encrypted_file_path)
|
299
|
+
puts decrypted_file
|
300
|
+
```
|
301
|
+
```ruby
|
302
|
+
# Get the file size in different units
|
303
|
+
file_size_bytes = read.file_size
|
304
|
+
puts file_size_bytes
|
305
|
+
|
306
|
+
file_size_kb = read.file_size(unit: :kilobytes)
|
307
|
+
puts file_size_kb
|
308
|
+
|
309
|
+
file_size_mb = read.file_size(unit: :megabytes)
|
310
|
+
puts file_size_mb
|
311
|
+
|
312
|
+
file_size_gb = read.file_size(unit: :gigabytes)
|
313
|
+
puts file_size_gb
|
314
|
+
```
|
315
|
+
|
316
|
+
## Error Handling
|
317
|
+
|
318
|
+
The Readlines library provides custom error classes to handle specific exceptions:
|
319
|
+
|
320
|
+
- `Readlines::Error`: General error class for all exceptions in the library.
|
321
|
+
- `Readlines::NotFoundError`: Raised when a file is not found.
|
322
|
+
- `Readlines::MissingFilePathError`: Raised when a file path is missing or empty.
|
323
|
+
- `Readlines::InvalidUnitError`: Raised when an invalid unit is provided for file size conversion.
|
324
|
+
|
325
|
+
These error classes help in handling and debugging exceptions that may occur while using the library.
|
326
|
+
|
327
|
+
## Contributing
|
328
|
+
|
329
|
+
Contributions to the Readlines library are welcome! If you find any bugs, have suggestions for improvements, or want to add new features, please open an issue or submit a pull request on the [GitHub repository](https://github.com/abo5/readlines).
|
330
|
+
|
331
|
+
When contributing, please ensure that your code follows the existing coding style and includes appropriate tests.
|
332
|
+
|
333
|
+
## License
|
334
|
+
|
335
|
+
The Readlines library is open-source and released under the [MIT License](https://opensource.org/licenses/MIT). You are free to use, modify, and distribute the library in accordance with the terms of the license.
|
336
|
+
|
337
|
+
## Contact
|
338
|
+
|
339
|
+
If you have any questions, suggestions, or feedback regarding the Readlines library, please feel free to contact the maintainer:
|
340
|
+
|
341
|
+
- Name: Maven
|
342
|
+
- Email: qppn@hotmail.com
|
343
|
+
- GitHub: [Maven's GitHub](https://github.com/abo5)
|
344
|
+
|
345
|
+
We appreciate your interest in the Readlines library and look forward to your contributions and feedback!
|
346
|
+
|
347
|
+
|
348
|
+
|
349
|
+
# readlines
|
data/Rakefile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'readlines'
|
2
|
+
|
3
|
+
# Create an instance of the ReadDuc
|
4
|
+
file_path = 'path/to/your/file.txt'
|
5
|
+
obj = Read.new(file_path)
|
6
|
+
|
7
|
+
# Example usage of the line_count method
|
8
|
+
begin
|
9
|
+
result = obj.line_count
|
10
|
+
puts "Result of line_count: #{result}"
|
11
|
+
rescue => e
|
12
|
+
puts "Error: #{e.message}"
|
13
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'readlines'
|
2
|
+
|
3
|
+
# Create an instance of the ReadDuc
|
4
|
+
file_path = 'path/to/your/file.txt'
|
5
|
+
obj = Read.new(file_path)
|
6
|
+
|
7
|
+
# Example usage of the replace method
|
8
|
+
begin
|
9
|
+
result = obj.replace
|
10
|
+
puts "Result of replace: #{result}"
|
11
|
+
rescue => e
|
12
|
+
puts "Error: #{e.message}"
|
13
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'readlines'
|
2
|
+
|
3
|
+
# Create an instance of the ReadDuc
|
4
|
+
file_path = 'path/to/your/file.txt'
|
5
|
+
obj = Read.new(file_path)
|
6
|
+
|
7
|
+
# Example usage of the replace_special_characters method
|
8
|
+
begin
|
9
|
+
result = obj.replace_special_characters
|
10
|
+
puts "Result of replace_special_characters: #{result}"
|
11
|
+
rescue => e
|
12
|
+
puts "Error: #{e.message}"
|
13
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'readlines'
|
2
|
+
|
3
|
+
# Create an instance of the ReadDuc
|
4
|
+
file_path = 'path/to/your/file.txt'
|
5
|
+
obj = Read.new(file_path)
|
6
|
+
|
7
|
+
# Example usage of the replace_multiple_patterns method
|
8
|
+
begin
|
9
|
+
result = obj.replace_multiple_patterns
|
10
|
+
puts "Result of replace_multiple_patterns: #{result}"
|
11
|
+
rescue => e
|
12
|
+
puts "Error: #{e.message}"
|
13
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'readlines'
|
2
|
+
|
3
|
+
# Create an instance of the ReadDuc
|
4
|
+
file_path = 'path/to/your/file.txt'
|
5
|
+
obj = Read.new(file_path)
|
6
|
+
|
7
|
+
# Example usage of the replace_csv_value method
|
8
|
+
begin
|
9
|
+
result = obj.replace_csv_value
|
10
|
+
puts "Result of replace_csv_value: #{result}"
|
11
|
+
rescue => e
|
12
|
+
puts "Error: #{e.message}"
|
13
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'readlines'
|
2
|
+
|
3
|
+
# Create an instance of the ReadDuc
|
4
|
+
file_path = 'path/to/your/file.txt'
|
5
|
+
obj = Read.new(file_path)
|
6
|
+
|
7
|
+
# Example usage of the delete_empty_lines method
|
8
|
+
begin
|
9
|
+
result = obj.delete_empty_lines
|
10
|
+
puts "Result of delete_empty_lines: #{result}"
|
11
|
+
rescue => e
|
12
|
+
puts "Error: #{e.message}"
|
13
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'readlines'
|
2
|
+
|
3
|
+
# Create an instance of the ReadDuc
|
4
|
+
file_path = 'path/to/your/file.txt'
|
5
|
+
obj = Read.new(file_path)
|
6
|
+
|
7
|
+
# Example usage of the delete_unwanted_characters method
|
8
|
+
begin
|
9
|
+
result = obj.delete_unwanted_characters
|
10
|
+
puts "Result of delete_unwanted_characters: #{result}"
|
11
|
+
rescue => e
|
12
|
+
puts "Error: #{e.message}"
|
13
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'readlines'
|
2
|
+
|
3
|
+
# Create an instance of the ReadDuc
|
4
|
+
file_path = 'path/to/your/file.txt'
|
5
|
+
obj = Read.new(file_path)
|
6
|
+
|
7
|
+
# Example usage of the delete_lines method
|
8
|
+
begin
|
9
|
+
result = obj.delete_lines
|
10
|
+
puts "Result of delete_lines: #{result}"
|
11
|
+
rescue => e
|
12
|
+
puts "Error: #{e.message}"
|
13
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'readlines'
|
2
|
+
|
3
|
+
# Create an instance of the ReadDuc
|
4
|
+
file_path = 'path/to/your/file.txt'
|
5
|
+
obj = Read.new(file_path)
|
6
|
+
|
7
|
+
# Example usage of the delete_duplicate_lines method
|
8
|
+
begin
|
9
|
+
result = obj.delete_duplicate_lines
|
10
|
+
puts "Result of delete_duplicate_lines: #{result}"
|
11
|
+
rescue => e
|
12
|
+
puts "Error: #{e.message}"
|
13
|
+
end
|