Module: SecurizeString::BinaryStringDataMethods::ClassMethods
- Defined in:
- lib/securize_string/binary_string_data_methods.rb
Overview
Adds basic binary data class methods via an include of SecurizeString::BinaryStringDataMethods.
Instance Method Summary collapse
-
#parse_data(mode = :data, value) ⇒ Object
Creates a data string from one many kinds of values: [:data] (default) The passed string value is directly used.
Instance Method Details
#parse_data(mode = :data, value) ⇒ Object
Creates a data string from one many kinds of values:
- :data
-
(default) The passed string value is directly used.
- :hex
-
Initialize using a hexidecimal string.
- :int
-
Initialize using the numeric value of the hexidecimal string.
- :base64
-
Initialize using the given base64 encoded data.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/securize_string/binary_string_data_methods.rb', line 21 def parse_data(mode = :data, value) case mode when :hex hex_string = value.to_s.delete('^0-9a-fA-F') data_string = [hex_string].pack('H' + hex_string.bytesize.to_s) when :data data_string = value.to_s when :int data_string = self.send(__method__, :hex, value.to_i.to_s(16)) when :base64 data_string = Base64.decode64(value.to_s) end return data_string end |