Class: Core::Utilities
- Inherits:
-
Object
- Object
- Core::Utilities
- Defined in:
- lib/core/utilities.rb
Class Method Summary collapse
-
.instance ⇒ Utilities
Returns the singleton instance of the Utilities class.
Instance Method Summary collapse
-
#initialize ⇒ Utilities
constructor
A new instance of Utilities.
-
#is_x_address?(x_address) ⇒ Boolean
Checks if a string is a valid X-address.
Constructor Details
#initialize ⇒ Utilities
9 10 11 |
# File 'lib/core/utilities.rb', line 9 def initialize @address_codec = AddressCodec.new end |
Class Method Details
.instance ⇒ Utilities
Returns the singleton instance of the Utilities class.
15 16 17 |
# File 'lib/core/utilities.rb', line 15 def self.instance @@instance ||= new end |
Instance Method Details
#is_x_address?(x_address) ⇒ Boolean
Checks if a string is a valid X-address.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/core/utilities.rb', line 22 def is_x_address?(x_address) return false unless x_address.is_a?(String) && x_address.start_with?('X') begin decoded = @address_codec.decode_x_address(x_address) return false if decoded[:account_id].nil? || decoded[:account_id].length != 20 tag = decoded[:tag] return false if tag && (tag < 0 || tag > MAX_32_BIT_UNSIGNED_INT) true rescue StandardError false end end |