Class: Solace::Tokens::Token

Inherits:
Object
  • Object
show all
Defined in:
lib/solace/tokens/token.rb

Overview

Represents a Solana token with its metadata.

A token object encapsulates the symbol and associated metadata for a Solana token. It provides dynamic access to metadata attributes via method calls. This class is used within the Solace::Tokens module to represent individual tokens loaded from a YAML configuration file.

Since:

  • 0.1.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(symbol, metadata) ⇒ self

Initializes a new Token instance.

Parameters:

  • symbol (String)

    The symbol of the token (e.g., ‘USDC’)

  • metadata (Hash)

    A hash containing the token’s metadata attributes

Since:

  • 0.1.0



20
21
22
23
# File 'lib/solace/tokens/token.rb', line 20

def initialize(symbol, )
  @symbol = symbol
  @metadata = .transform_keys(&:to_sym)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name) ⇒ Object

Dynamically access metadata attributes.

Parameters:

  • name (Symbol)

    The name of the metadata attribute

Returns:

  • (Object)

    The value of the metadata attribute if it exists

Raises:

  • (NoMethodError)

    If the attribute does not exist

Since:

  • 0.1.0



30
31
32
33
34
# File 'lib/solace/tokens/token.rb', line 30

def method_missing(name, *)
  return [name] if .key?(name)

  super
end

Instance Attribute Details

#metadataObject (readonly)

Since:

  • 0.1.0



13
14
15
# File 'lib/solace/tokens/token.rb', line 13

def 
  @metadata
end

#symbolObject (readonly)

Since:

  • 0.1.0



13
14
15
# File 'lib/solace/tokens/token.rb', line 13

def symbol
  @symbol
end

Instance Method Details

#inspectString

Returns a string representation of the Token object.

Returns:

  • (String)

    The string representation of the Token

Since:

  • 0.1.0



48
49
50
# File 'lib/solace/tokens/token.rb', line 48

def inspect
  "#<Solace::Token #{symbol} #{.inspect}>"
end

#respond_to_missing?(name, _include_private = false) ⇒ Boolean

Check if a metadata attribute exists.

Parameters:

  • name (Symbol)

    The name of the metadata attribute

  • _include_private (Boolean) (defaults to: false)

    Whether to include private methods (not used)

Returns:

  • (Boolean)

    True if the attribute exists, false otherwise

Since:

  • 0.1.0



41
42
43
# File 'lib/solace/tokens/token.rb', line 41

def respond_to_missing?(name, _include_private = false)
  .key?(name) || super
end