Class: Systemdy::Utility::Formatter
- Inherits:
-
Object
- Object
- Systemdy::Utility::Formatter
- Defined in:
- lib/systemdy/utility/formatter.rb
Overview
Allows to formatting provided data into another type
Class Method Summary collapse
-
.remove_newline_from_system_command(system_call) ⇒ String
method for remove
\ncharacters from system calls. -
.return_an_array_from(string_to_parse, argument_splitter: '\n', remove_blank_elements: true) ⇒ Array
method for convert a string into an array without blank elements.
-
.return_an_array_from_system_command(system_call) ⇒ Array
method for convert system calls into an array.
Class Method Details
.remove_newline_from_system_command(system_call) ⇒ String
TODO:
execute system calls with backtick instead of system() beacuse system() return only true or false and not the expected value
method for remove \n characters from system calls
40 41 42 |
# File 'lib/systemdy/utility/formatter.rb', line 40 def self.remove_newline_from_system_command(system_call) system_call.chomp! # remove \n from system call returned value end |
.return_an_array_from(string_to_parse, argument_splitter: '\n', remove_blank_elements: true) ⇒ Array
method for convert a string into an array without blank elements
29 30 31 |
# File 'lib/systemdy/utility/formatter.rb', line 29 def self.return_an_array_from(string_to_parse, argument_splitter: '\n', remove_blank_elements: true) remove_blank_elements ? string_to_parse.split(/#{argument_splitter}/).reject(&:empty?) : string_to_parse.split(/#{argument_splitter}/) end |
.return_an_array_from_system_command(system_call) ⇒ Array
TODO:
execute system calls with backtick instead of system() beacuse system() return only true or false and not the expected value
method for convert system calls into an array
13 14 15 16 17 |
# File 'lib/systemdy/utility/formatter.rb', line 13 def self.return_an_array_from_system_command(system_call) system_call_without_new_line = remove_newline_from_system_command(system_call) # remove \n from system call returned value return system_call_without_new_line if !$?.success? # return system error message if the process has non-zero exit status return_an_array_from(system_call_without_new_line) # convert values returned by `` system call to an array-based list based on argument_splitter value end |