Class: TonSdkRuby::Mask
- Inherits:
-
Object
- Object
- TonSdkRuby::Mask
- Extended by:
- TonSdkRuby
- Includes:
- TonSdkRuby
- Defined in:
- lib/ton-sdk-ruby/boc/mask.rb
Constant Summary
Constants included from TonSdkRuby
DEPTH_BITS, FLAG_BOUNCEABLE, FLAG_NON_BOUNCEABLE, FLAG_TEST_ONLY, HASH_BITS, INT32_MAX, INT32_MIN, LEAN_BOC_MAGIC_PREFIX, LEAN_BOC_MAGIC_PREFIX_CRC, REACH_BOC_MAGIC_PREFIX, VERSION
Instance Attribute Summary collapse
-
#hash_count ⇒ Object
Returns the value of attribute hash_count.
-
#hash_index ⇒ Object
Returns the value of attribute hash_index.
-
#value ⇒ Object
Returns the value of attribute value.
Instance Method Summary collapse
- #apply(level) ⇒ Object
-
#initialize(mask) ⇒ Mask
constructor
A new instance of Mask.
- #is_significant(level) ⇒ Object
- #level ⇒ Object
Methods included from TonSdkRuby
augment, base64_to_bytes, bits_to_big_int, bits_to_big_uint, bits_to_bytes, bits_to_hex, bits_to_int_uint, breadth_first_sort, bytes_compare, bytes_needed_for_words_bip39, bytes_to_base64, bytes_to_bits, bytes_to_data_string, bytes_to_hex, bytes_to_string, bytes_to_uint, crc16, crc16_bytes_be, crc32c, crc32c_bytes_le, depth_first_sort, deserialize, deserialize_cell, deserialize_fift, deserialize_header, generate_words_bip39, get_mapper, hex_to_bits, hex_to_bytes, hex_to_data_string, read_json_from_link, read_post_json_from_link, require_type, rollback, serialize, serialize_cell, sha256, sha512, sign_cell, slice_into_chunks, string_to_bytes, uint_to_hex, validate_library_reference, validate_merkle_proof, validate_merkle_update, validate_ordinary, validate_pruned_branch
Constructor Details
#initialize(mask) ⇒ Mask
Returns a new instance of Mask.
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/ton-sdk-ruby/boc/mask.rb', line 8 def initialize(mask) if mask.class.to_s.downcase == "mask" @value = mask.value elsif mask.class.to_s.downcase == "integer" @value = mask end @hash_index = count_set_bits(value) @hash_count = @hash_index + 1 end |
Instance Attribute Details
#hash_count ⇒ Object
Returns the value of attribute hash_count.
6 7 8 |
# File 'lib/ton-sdk-ruby/boc/mask.rb', line 6 def hash_count @hash_count end |
#hash_index ⇒ Object
Returns the value of attribute hash_index.
6 7 8 |
# File 'lib/ton-sdk-ruby/boc/mask.rb', line 6 def hash_index @hash_index end |
#value ⇒ Object
Returns the value of attribute value.
6 7 8 |
# File 'lib/ton-sdk-ruby/boc/mask.rb', line 6 def value @value end |
Instance Method Details
#apply(level) ⇒ Object
27 28 29 |
# File 'lib/ton-sdk-ruby/boc/mask.rb', line 27 def apply(level) Mask.new(self.value & ((1 << level) - 1)) end |
#is_significant(level) ⇒ Object
23 24 25 |
# File 'lib/ton-sdk-ruby/boc/mask.rb', line 23 def is_significant(level) level == 0 || (self.value >> (level - 1)) % 2 != 0 end |
#level ⇒ Object
19 20 21 |
# File 'lib/ton-sdk-ruby/boc/mask.rb', line 19 def level 32 - clz(value) end |