Class: Readlines::ReadDuc
- Inherits:
-
Object
- Object
- Readlines::ReadDuc
- Defined in:
- lib/readlines/read.rb
Instance Attribute Summary collapse
-
#file_path ⇒ Object
readonly
Returns the value of attribute file_path.
Instance Method Summary collapse
- #character_count(line_specific: false) ⇒ Object
-
#check_spelling(dictionary) ⇒ Object
Spelling operations.
-
#convert_encoding(from_encoding, to_encoding) ⇒ Object
Convert operations.
- #convert_to_array ⇒ Object
- #convert_to_format(format) ⇒ Object
- #decrypt_content(key, encrypted_file_path) ⇒ Object
- #delete_csv_columns(column_indices) ⇒ Object
- #delete_duplicate_lines ⇒ Object
-
#delete_empty_lines ⇒ Object
Delete operations.
- #delete_lines(line_numbers, delete_space: false) ⇒ Object
- #delete_right_left_separator(separator, delete_right: false, delete_left: false, keep_separator: false) ⇒ Object
- #delete_unwanted_characters(characters) ⇒ Object
-
#encrypt_content(key) ⇒ Object
Encryption operations.
- #extract_patterns(patterns) ⇒ Object
-
#file_size(unit = nil) ⇒ Object
File operations.
- #file_statistics ⇒ Object
- #info ⇒ Object
-
#initialize(file_path, count: nil, split: nil) ⇒ ReadDuc
constructor
A new instance of ReadDuc.
-
#line_count ⇒ Object
Count operations.
-
#merge_files(file_paths) ⇒ Object
Merge operations.
- #merge_files_with_specific_line(file_paths, separator: "\n") ⇒ Object
-
#pattern_exists?(pattern) ⇒ Boolean
Pattern operations.
-
#read_lines ⇒ Object
Read operations.
-
#replace(pattern, replacement) ⇒ Object
Replace operations.
- #replace_csv_value(column_index, old_value, new_value) ⇒ Object
- #replace_multiple_patterns(pattern_replacement_hash) ⇒ Object
- #replace_special_characters(replacement) ⇒ Object
-
#reverse_content ⇒ Object
Content operations.
-
#search_about(value, show_lines: false) ⇒ Object
Search operations.
- #search_in_range(start_line, end_line, pattern) ⇒ Object
- #search_logical_patterns(patterns, operator) ⇒ Object
- #search_multiple_patterns(patterns) ⇒ Object
-
#sort_alphabetically ⇒ Object
Sort operations.
- #split_by_delimiter(delimiter) ⇒ Object
- #split_by_pattern(pattern) ⇒ Object
-
#split_file(num_parts) ⇒ Object
Split operations.
- #split_file_by_size(part_size) ⇒ Object
- #validate_content(rules) ⇒ Object
- #word_count(line_specific: false) ⇒ Object
Methods included from Content
#decrypt_content_now, #encrypt_content_now, #reverse_content_now, #validate_content_now
Methods included from Split
#split_by_delimiter_now, #split_by_pattern_now, #split_file_by_size_now, #split_file_now
Methods included from Sort
Methods included from Pattern
#extract_patterns_now, #pattern_exists_now?
Methods included from Info
Methods included from Merge
#merge_files_now, #merge_files_with_specific_line_now
Methods included from File
Methods included from Replace
#replace_csv_value_now, #replace_multiple_patterns_now, #replace_now, #replace_special_characters_now
Methods included from Search
#search_about_now, #search_in_range_now, #search_logical_patterns_now, #search_multiple_patterns_now
Methods included from Convert
#convert_encoding_now, #convert_to_array_now, #convert_to_format_now
Methods included from Delete
#delete_csv_columns_now, #delete_duplicate_lines_now, #delete_empty_lines_now, #delete_lines_now, #delete_right_left_separator_now, #delete_unwanted_characters_now
Methods included from Count
#character_count_now, #line_count_now, #read_lines_now, #word_count_now
Constructor Details
#initialize(file_path, count: nil, split: nil) ⇒ ReadDuc
Returns a new instance of ReadDuc.
35 36 37 38 39 40 41 |
# File 'lib/readlines/read.rb', line 35 def initialize(file_path, count: nil, split: nil) raise Readlines::Error::MissingFilePathError, 'You should provide a file path, e.g., "/path/to/file.txt"' if file_path.nil? || file_path.empty? @file_path = file_path @count_keyword = count @split_delimiter = split end |
Instance Attribute Details
#file_path ⇒ Object (readonly)
Returns the value of attribute file_path.
33 34 35 |
# File 'lib/readlines/read.rb', line 33 def file_path @file_path end |
Instance Method Details
#character_count(line_specific: false) ⇒ Object
62 63 64 65 |
# File 'lib/readlines/read.rb', line 62 def character_count(line_specific: false) raise Readlines::Error::NotFoundError, "File not found: #{@file_path}" unless ::File.exist?(@file_path) character_count_now(line_specific: line_specific) end |
#check_spelling(dictionary) ⇒ Object
Spelling operations
247 248 249 250 |
# File 'lib/readlines/read.rb', line 247 def check_spelling(dictionary) raise Readlines::Error::NotFoundError, "File not found: #{@file_path}" unless ::File.exist?(@file_path) check_spelling_now(dictionary) end |
#convert_encoding(from_encoding, to_encoding) ⇒ Object
Convert operations
198 199 200 201 |
# File 'lib/readlines/read.rb', line 198 def convert_encoding(from_encoding, to_encoding) raise Readlines::Error::NotFoundError, "File not found: #{@file_path}" unless ::File.exist?(@file_path) convert_encoding_now(from_encoding, to_encoding) end |
#convert_to_array ⇒ Object
208 209 210 211 |
# File 'lib/readlines/read.rb', line 208 def convert_to_array raise Readlines::Error::NotFoundError, "File not found: #{@file_path}" unless ::File.exist?(@file_path) convert_to_array_now() end |
#convert_to_format(format) ⇒ Object
203 204 205 206 |
# File 'lib/readlines/read.rb', line 203 def convert_to_format(format) raise Readlines::Error::NotFoundError, "File not found: #{@file_path}" unless ::File.exist?(@file_path) convert_to_format_now(format) end |
#decrypt_content(key, encrypted_file_path) ⇒ Object
258 259 260 261 |
# File 'lib/readlines/read.rb', line 258 def decrypt_content(key, encrypted_file_path) raise Readlines::Error::NotFoundError, "File not found: #{encrypted_file_path}" unless ::File.exist?(encrypted_file_path) decrypt_content_now(key, encrypted_file_path) end |
#delete_csv_columns(column_indices) ⇒ Object
147 148 149 150 |
# File 'lib/readlines/read.rb', line 147 def delete_csv_columns(column_indices) raise Readlines::Error::NotFoundError, "File not found: #{@file_path}" unless ::File.exist?(@file_path) delete_csv_columns_now(column_indices) end |
#delete_duplicate_lines ⇒ Object
142 143 144 145 |
# File 'lib/readlines/read.rb', line 142 def delete_duplicate_lines raise Readlines::Error::NotFoundError, "File not found: #{@file_path}" unless ::File.exist?(@file_path) delete_duplicate_lines_now() end |
#delete_empty_lines ⇒ Object
Delete operations
127 128 129 130 |
# File 'lib/readlines/read.rb', line 127 def delete_empty_lines raise Readlines::Error::NotFoundError, "File not found: #{@file_path}" unless ::File.exist?(@file_path) delete_empty_lines_now() end |
#delete_lines(line_numbers, delete_space: false) ⇒ Object
137 138 139 140 |
# File 'lib/readlines/read.rb', line 137 def delete_lines(line_numbers, delete_space: false) raise Readlines::Error::NotFoundError, "File not found: #{@file_path}" unless ::File.exist?(@file_path) delete_lines_now(line_numbers, delete_space: delete_space) end |
#delete_right_left_separator(separator, delete_right: false, delete_left: false, keep_separator: false) ⇒ Object
152 153 154 155 |
# File 'lib/readlines/read.rb', line 152 def delete_right_left_separator(separator, delete_right: false, delete_left: false, keep_separator: false) raise Readlines::Error::NotFoundError, "File not found: #{@file_path}" unless ::File.exist?(@file_path) delete_right_left_separator_now(separator, delete_right: delete_right, delete_left: delete_left, keep_separator: keep_separator) end |
#delete_unwanted_characters(characters) ⇒ Object
132 133 134 135 |
# File 'lib/readlines/read.rb', line 132 def delete_unwanted_characters(characters) raise Readlines::Error::NotFoundError, "File not found: #{@file_path}" unless ::File.exist?(@file_path) delete_unwanted_characters_now(characters) end |
#encrypt_content(key) ⇒ Object
Encryption operations
253 254 255 256 |
# File 'lib/readlines/read.rb', line 253 def encrypt_content(key) raise Readlines::Error::NotFoundError, "File not found: #{@file_path}" unless ::File.exist?(@file_path) encrypt_content_now(key) end |
#extract_patterns(patterns) ⇒ Object
230 231 232 233 |
# File 'lib/readlines/read.rb', line 230 def extract_patterns(patterns) raise Readlines::Error::NotFoundError, "File not found: #{@file_path}" unless ::File.exist?(@file_path) extract_patterns_now(patterns) end |
#file_size(unit = nil) ⇒ Object
File operations
214 215 216 217 |
# File 'lib/readlines/read.rb', line 214 def file_size(unit = nil) raise Readlines::Error::NotFoundError, "File not found: #{@file_path}" unless ::File.exist?(@file_path) file_size_now(unit) end |
#file_statistics ⇒ Object
219 220 221 222 |
# File 'lib/readlines/read.rb', line 219 def file_statistics raise Readlines::Error::NotFoundError, "File not found: #{@file_path}" unless ::File.exist?(@file_path) file_statistics_now() end |
#info ⇒ Object
78 79 80 81 |
# File 'lib/readlines/read.rb', line 78 def info raise Readlines::Error::NotFoundError, "File not found: #{@file_path}" unless ::File.exist?(@file_path) info_now() end |
#line_count ⇒ Object
Count operations
57 58 59 60 |
# File 'lib/readlines/read.rb', line 57 def line_count raise Readlines::Error::NotFoundError, "File not found: #{@file_path}" unless ::File.exist?(@file_path) line_count_now() end |
#merge_files(file_paths) ⇒ Object
Merge operations
187 188 189 190 |
# File 'lib/readlines/read.rb', line 187 def merge_files(file_paths) raise ArgumentError, "File paths array is empty" if file_paths.empty? merge_files_now(file_paths) end |
#merge_files_with_specific_line(file_paths, separator: "\n") ⇒ Object
192 193 194 195 |
# File 'lib/readlines/read.rb', line 192 def merge_files_with_specific_line(file_paths, separator: "\n") raise ArgumentError, "File paths array is empty" if file_paths.empty? merge_files_with_specific_line_now(file_paths, separator: separator) end |
#pattern_exists?(pattern) ⇒ Boolean
Pattern operations
225 226 227 228 |
# File 'lib/readlines/read.rb', line 225 def pattern_exists?(pattern) raise Readlines::Error::NotFoundError, "File not found: #{@file_path}" unless ::File.exist?(@file_path) pattern_exists_now?(pattern) end |
#read_lines ⇒ Object
Read operations
73 74 75 76 |
# File 'lib/readlines/read.rb', line 73 def read_lines raise Readlines::Error::NotFoundError, "File not found: #{@file_path}" unless ::File.exist?(@file_path) read_lines_now() end |
#replace(pattern, replacement) ⇒ Object
Replace operations
106 107 108 109 |
# File 'lib/readlines/read.rb', line 106 def replace(pattern, replacement) raise Readlines::Error::NotFoundError, "File not found: #{@file_path}" unless ::File.exist?(@file_path) replace_now(pattern, replacement) end |
#replace_csv_value(column_index, old_value, new_value) ⇒ Object
121 122 123 124 |
# File 'lib/readlines/read.rb', line 121 def replace_csv_value(column_index, old_value, new_value) raise Readlines::Error::NotFoundError, "File not found: #{@file_path}" unless ::File.exist?(@file_path) replace_csv_value_now(column_index, old_value, new_value) end |
#replace_multiple_patterns(pattern_replacement_hash) ⇒ Object
116 117 118 119 |
# File 'lib/readlines/read.rb', line 116 def replace_multiple_patterns(pattern_replacement_hash) raise Readlines::Error::NotFoundError, "File not found: #{@file_path}" unless ::File.exist?(@file_path) replace_multiple_patterns_now(pattern_replacement_hash) end |
#replace_special_characters(replacement) ⇒ Object
111 112 113 114 |
# File 'lib/readlines/read.rb', line 111 def replace_special_characters(replacement) raise Readlines::Error::NotFoundError, "File not found: #{@file_path}" unless ::File.exist?(@file_path) replace_special_characters_now(replacement) end |
#reverse_content ⇒ Object
Content operations
236 237 238 239 |
# File 'lib/readlines/read.rb', line 236 def reverse_content raise Readlines::Error::NotFoundError, "File not found: #{@file_path}" unless ::File.exist?(@file_path) reverse_content_now() end |
#search_about(value, show_lines: false) ⇒ Object
Search operations
84 85 86 87 |
# File 'lib/readlines/read.rb', line 84 def search_about(value, show_lines: false) raise Readlines::Error::NotFoundError, "File not found: #{@file_path}" unless ::File.exist?(@file_path) search_about_now(value, show_lines: show_lines) end |
#search_in_range(start_line, end_line, pattern) ⇒ Object
94 95 96 97 |
# File 'lib/readlines/read.rb', line 94 def search_in_range(start_line, end_line, pattern) raise Readlines::Error::NotFoundError, "File not found: #{@file_path}" unless ::File.exist?(@file_path) search_in_range_now(start_line, end_line, pattern) end |
#search_logical_patterns(patterns, operator) ⇒ Object
99 100 101 102 103 |
# File 'lib/readlines/read.rb', line 99 def search_logical_patterns(patterns, operator) raise Readlines::Error::NotFoundError, "File not found: #{@file_path}" unless ::File.exist?(@file_path) raise ArgumentError, "Invalid logical operator: #{operator}" unless %w[AND OR].include?(operator) search_logical_patterns_now(patterns, operator) end |
#search_multiple_patterns(patterns) ⇒ Object
89 90 91 92 |
# File 'lib/readlines/read.rb', line 89 def search_multiple_patterns(patterns) raise Readlines::Error::NotFoundError, "File not found: #{@file_path}" unless ::File.exist?(@file_path) search_multiple_patterns_now(patterns) end |
#sort_alphabetically ⇒ Object
Sort operations
158 159 160 161 |
# File 'lib/readlines/read.rb', line 158 def sort_alphabetically raise Readlines::Error::NotFoundError, "File not found: #{@file_path}" unless ::File.exist?(@file_path) sort_alphabetically_now() end |
#split_by_delimiter(delimiter) ⇒ Object
176 177 178 179 |
# File 'lib/readlines/read.rb', line 176 def split_by_delimiter(delimiter) raise Readlines::Error::NotFoundError, "File not found: #{@file_path}" unless ::File.exist?(@file_path) split_by_delimiter_now(delimiter) end |
#split_by_pattern(pattern) ⇒ Object
181 182 183 184 |
# File 'lib/readlines/read.rb', line 181 def split_by_pattern(pattern) raise Readlines::Error::NotFoundError, "File not found: #{@file_path}" unless ::File.exist?(@file_path) split_by_pattern_now(pattern) end |
#split_file(num_parts) ⇒ Object
Split operations
164 165 166 167 168 |
# File 'lib/readlines/read.rb', line 164 def split_file(num_parts) raise Readlines::Error::NotFoundError, "File not found: #{@file_path}" unless ::File.exist?(@file_path) raise ArgumentError, "Number of parts must be greater than 0" if num_parts <= 0 split_file_now(num_parts) end |
#split_file_by_size(part_size) ⇒ Object
170 171 172 173 174 |
# File 'lib/readlines/read.rb', line 170 def split_file_by_size(part_size) raise Readlines::Error::NotFoundError, "File not found: #{@file_path}" unless ::File.exist?(@file_path) raise ArgumentError, "Part size must be greater than 0" if part_size <= 0 split_file_by_size_now(part_size) end |
#validate_content(rules) ⇒ Object
241 242 243 244 |
# File 'lib/readlines/read.rb', line 241 def validate_content(rules) raise Readlines::Error::NotFoundError, "File not found: #{@file_path}" unless ::File.exist?(@file_path) validate_content_now(rules) end |
#word_count(line_specific: false) ⇒ Object
67 68 69 70 |
# File 'lib/readlines/read.rb', line 67 def word_count(line_specific: false) raise Readlines::Error::NotFoundError, "File not found: #{@file_path}" unless ::File.exist?(@file_path) word_count_now(line_specific: line_specific) end |