Module: CharshiftHelper
- Defined in:
- lib/charshifthelper.rb
Class Method Summary collapse
- .check_for_uniqueness(string_array) ⇒ Object
- .check_for_valid_array_elements(string_array) ⇒ Object
- .confirm_fixnum(input_val) ⇒ Object
- .encoding_ind_split(input_string) ⇒ Object
- .get_char_by_ord(ordinal_value, char_encoding_type) ⇒ Object
- .get_encoding(string) ⇒ Object
- .get_encoding_length(encoding) ⇒ Object
- .get_ord_by_char(character) ⇒ Object
- .get_shift_distance_minus_loops(input_val, collection_length) ⇒ Object
- .get_shift_position(starting_pos, shift_val, encoding_length) ⇒ Object
Class Method Details
.check_for_uniqueness(string_array) ⇒ Object
90 91 92 |
# File 'lib/charshifthelper.rb', line 90 def self.check_for_uniqueness string_array return string_array.uniq.length == string_array.length end |
.check_for_valid_array_elements(string_array) ⇒ Object
81 82 83 84 85 86 87 88 |
# File 'lib/charshifthelper.rb', line 81 def self.check_for_valid_array_elements string_array string_array.each do |chr| if !chr.is_a?(String) || chr.length != 1 return false end end return true end |
.confirm_fixnum(input_val) ⇒ Object
3 4 5 6 7 8 9 |
# File 'lib/charshifthelper.rb', line 3 def self.confirm_fixnum input_val if !input_val.instance_of? Fixnum raise TypeError, 'Input value must be of type fixnum' else return true end end |
.encoding_ind_split(input_string) ⇒ Object
11 12 13 14 15 16 17 18 |
# File 'lib/charshifthelper.rb', line 11 def self.encoding_ind_split input_string split_string = [] input_string.each_char do |chr| split_string << chr end return split_string end |
.get_char_by_ord(ordinal_value, char_encoding_type) ⇒ Object
45 46 47 |
# File 'lib/charshifthelper.rb', line 45 def self.get_char_by_ord ordinal_value, char_encoding_type return ordinal_value.chr(char_encoding_type) end |
.get_encoding(string) ⇒ Object
53 54 55 |
# File 'lib/charshifthelper.rb', line 53 def self.get_encoding string return string.encoding.to_s end |
.get_encoding_length(encoding) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/charshifthelper.rb', line 57 def self.get_encoding_length encoding max = 100000000000 min = 0 guess = 50000000000 while true begin guess.chr(encoding) if (min > max) return max + 1 else min = guess + 1 guess = (max + min) / 2 end rescue if min > max return max + 1 else max = guess - 1 guess = (max + min) / 2 end end end end |
.get_ord_by_char(character) ⇒ Object
49 50 51 |
# File 'lib/charshifthelper.rb', line 49 def self.get_ord_by_char character return character.ord end |
.get_shift_distance_minus_loops(input_val, collection_length) ⇒ Object
20 21 22 23 24 25 26 27 28 |
# File 'lib/charshifthelper.rb', line 20 def self.get_shift_distance_minus_loops input_val, collection_length absloute_input_val = input_val.abs remaining_difference = absloute_input_val % collection_length if absloute_input_val > collection_length return input_val > 0 ? remaining_difference : 0 - remaining_difference else return input_val end end |
.get_shift_position(starting_pos, shift_val, encoding_length) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/charshifthelper.rb', line 30 def self.get_shift_position starting_pos, shift_val, encoding_length collection_length = encoding_length shift_difference = self.get_shift_distance_minus_loops(shift_val, collection_length) start_plus_shift = starting_pos + shift_difference if shift_difference + starting_pos == encoding_length return 0 elsif start_plus_shift > collection_length return 0 + start_plus_shift - collection_length elsif start_plus_shift < 0 return collection_length + start_plus_shift else return start_plus_shift end end |