Class: Solrengine::Ui::BalanceComponent
- Inherits:
-
ViewComponent::Base
- Object
- ViewComponent::Base
- Solrengine::Ui::BalanceComponent
- Defined in:
- app/components/solrengine/ui/balance_component.rb
Constant Summary collapse
- LAMPORTS_PER_SOL =
1_000_000_000- SIZE_CLASSES =
{ sm: "text-sm", md: "text-xl", lg: "text-3xl" }.freeze
Instance Attribute Summary collapse
-
#show_symbol ⇒ Object
readonly
Returns the value of attribute show_symbol.
-
#size ⇒ Object
readonly
Returns the value of attribute size.
Instance Method Summary collapse
- #formatted_amount ⇒ Object
-
#initialize(lamports: nil, sol: nil, show_symbol: true, size: :md) ⇒ BalanceComponent
constructor
A new instance of BalanceComponent.
- #size_class ⇒ Object
- #sol_amount ⇒ Object
Constructor Details
#initialize(lamports: nil, sol: nil, show_symbol: true, size: :md) ⇒ BalanceComponent
Returns a new instance of BalanceComponent.
15 16 17 18 19 20 |
# File 'app/components/solrengine/ui/balance_component.rb', line 15 def initialize(lamports: nil, sol: nil, show_symbol: true, size: :md) @lamports = lamports @sol = sol @show_symbol = show_symbol @size = size end |
Instance Attribute Details
#show_symbol ⇒ Object (readonly)
Returns the value of attribute show_symbol.
13 14 15 |
# File 'app/components/solrengine/ui/balance_component.rb', line 13 def show_symbol @show_symbol end |
#size ⇒ Object (readonly)
Returns the value of attribute size.
13 14 15 |
# File 'app/components/solrengine/ui/balance_component.rb', line 13 def size @size end |
Instance Method Details
#formatted_amount ⇒ Object
32 33 34 |
# File 'app/components/solrengine/ui/balance_component.rb', line 32 def formatted_amount format("%.9f", sol_amount).sub(/0+\z/, "").sub(/\.\z/, ".0") end |
#size_class ⇒ Object
36 37 38 |
# File 'app/components/solrengine/ui/balance_component.rb', line 36 def size_class SIZE_CLASSES.fetch(size, SIZE_CLASSES[:md]) end |
#sol_amount ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'app/components/solrengine/ui/balance_component.rb', line 22 def sol_amount if @lamports @lamports.to_f / LAMPORTS_PER_SOL elsif @sol @sol.to_f else 0.0 end end |