class String

Public Instance Methods

bth() click to toggle source

binary convert to hex string

# File lib/tapyrus.rb, line 101
def bth
  unpack('H*').first
end
bti() click to toggle source

binary convert to integer

# File lib/tapyrus.rb, line 111
def bti
  bth.to_i(16)
end
htb() click to toggle source

hex string convert to binary

# File lib/tapyrus.rb, line 106
def htb
  [self].pack('H*')
end
opcode() click to toggle source

get opcode

# File lib/tapyrus.rb, line 121
def opcode
  force_encoding(Encoding::ASCII_8BIT).ord
end
opcode?() click to toggle source
# File lib/tapyrus.rb, line 125
def opcode?
  !pushdata?
end
push_opcode?() click to toggle source
# File lib/tapyrus.rb, line 129
def push_opcode?
  [Tapyrus::Opcodes::OP_PUSHDATA1, Tapyrus::Opcodes::OP_PUSHDATA2, Tapyrus::Opcodes::OP_PUSHDATA4].include?(opcode)
end
pushdata?() click to toggle source

whether data push only?

# File lib/tapyrus.rb, line 134
def pushdata?
  opcode <= Tapyrus::Opcodes::OP_PUSHDATA4 && opcode > Tapyrus::Opcodes::OP_0
end
pushed_data() click to toggle source
# File lib/tapyrus.rb, line 138
def pushed_data
  return nil unless pushdata?
  offset = 1
  case opcode
  when Tapyrus::Opcodes::OP_PUSHDATA1
    offset += 1
  when Tapyrus::Opcodes::OP_PUSHDATA2
    offset += 2
  when Tapyrus::Opcodes::OP_PUSHDATA4
    offset += 4
  end
  self[offset..-1]
end
rhex() click to toggle source

reverse hex string endian

# File lib/tapyrus.rb, line 116
def rhex
  htb.reverse.bth
end
valid_hex?() click to toggle source

whether value is hex or not hex @return [Boolean] return true if data is hex

# File lib/tapyrus.rb, line 154
def valid_hex?
  !self[/\H/]
end