Class: Eth::Address
- Inherits:
-
Object
- Object
- Eth::Address
- Defined in:
- lib/eth/address.rb
Instance Method Summary collapse
- #checksummed ⇒ Object
-
#initialize(address) ⇒ Address
constructor
A new instance of Address.
- #valid? ⇒ Boolean
Constructor Details
#initialize(address) ⇒ Address
Returns a new instance of Address.
4 5 6 |
# File 'lib/eth/address.rb', line 4 def initialize(address) @address = Utils.prefix_hex(address) end |
Instance Method Details
#checksummed ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'lib/eth/address.rb', line 18 def checksummed raise "Invalid address: #{address}" unless matches_any_format? cased = unprefixed.chars.zip(checksum.chars).map do |char, check| check.match(/[0-7]/) ? char.downcase : char.upcase end Utils.prefix_hex(cased.join) end |
#valid? ⇒ Boolean
8 9 10 11 12 13 14 15 16 |
# File 'lib/eth/address.rb', line 8 def valid? if !matches_any_format? false elsif not_checksummed? true else checksum_matches? end end |