class TezosClient::Tools::ConvertToHash::Base

Attributes

data[RW]
type[RW]

Public Class Methods

new(data:, type:) click to toggle source
# File lib/tezos_client/tools/convert_to_hash/base.rb, line 7
def initialize(data:, type:)
  @data = data
  @type = type
end

Public Instance Methods

value() click to toggle source
# File lib/tezos_client/tools/convert_to_hash/base.rb, line 14
def value
  anonymous? ? decode : { var_name => decode }
end

Protected Instance Methods

anonymous?() click to toggle source
# File lib/tezos_client/tools/convert_to_hash/base.rb, line 29
def anonymous?
  !(type.key?(:annots) && type[:annots].any?)
end
decode() click to toggle source
# File lib/tezos_client/tools/convert_to_hash/base.rb, line 19
def decode
  klass.new(
    data: data,
    type: type
  ).decode

rescue NameError
  raise NotImplementedError, "type '#{type[:prim]}' not implemented"
end
var_name() click to toggle source
# File lib/tezos_client/tools/convert_to_hash/base.rb, line 37
def var_name
  return nil if anonymous?

  "#{var_name_annot[1..-1]}".to_sym
end
var_name_annot() click to toggle source
# File lib/tezos_client/tools/convert_to_hash/base.rb, line 33
def var_name_annot
  type[:annots].first
end

Private Instance Methods

klass() click to toggle source
# File lib/tezos_client/tools/convert_to_hash/base.rb, line 44
def klass
  "#{self.class.name.deconstantize}::#{type[:prim].camelize}".constantize
end