Class: OnlyofficeFileHelper::StringHelper
- Inherits:
-
Object
- Object
- OnlyofficeFileHelper::StringHelper
- Defined in:
- lib/onlyoffice_file_helper/string_helper.rb
Overview
Helper for Strings
Class Method Summary collapse
- .generate_random_number(value = nil) ⇒ Object
- .generate_random_string(length_string = 32) ⇒ Object
-
.get_result_string_of_comparison(compare_parameter, first_element, second_element, accuracy = 0.01) ⇒ String
Return ‘Result’ String of comparison of two strings.
- .to_bool(string) ⇒ Object
Class Method Details
.generate_random_number(value = nil) ⇒ Object
11 12 13 |
# File 'lib/onlyoffice_file_helper/string_helper.rb', line 11 def generate_random_number(value = nil) "#{value}: #{Time.now.nsec}" end |
.generate_random_string(length_string = 32) ⇒ Object
7 8 9 |
# File 'lib/onlyoffice_file_helper/string_helper.rb', line 7 def generate_random_string(length_string = 32) (0...length_string).map { (('a'..'z').to_a + ('A'..'Z').to_a)[rand(52)] }.join end |
.get_result_string_of_comparison(compare_parameter, first_element, second_element, accuracy = 0.01) ⇒ String
Return ‘Result’ String of comparison of two strings
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/onlyoffice_file_helper/string_helper.rb', line 20 def get_result_string_of_comparison(compare_parameter, first_element, second_element, accuracy = 0.01) if first_element.is_a?(Float) && second_element.is_a?(Float) difference = (first_element - second_element).abs difference >= accuracy ? "Difference between parameters in #{compare_parameter} is #{difference}" : '' elsif first_element.to_s == second_element.to_s '' else "Difference in #{compare_parameter}. From case: #{first_element}. From result: #{second_element}" end end |
.to_bool(string) ⇒ Object
31 32 33 34 35 36 37 38 |
# File 'lib/onlyoffice_file_helper/string_helper.rb', line 31 def to_bool(string) str = string.to_s if str.casecmp('false').zero? false elsif str.casecmp('true').zero? true end end |