Module: ClaudeUsage::Formatters
- Defined in:
- lib/claude_usage/formatters.rb
Overview
Shared formatting utilities for displaying usage data
Class Method Summary collapse
-
.format_currency(amount) ⇒ Object
Format a dollar amount with 2 decimal places Example: 1.234 => “$1.23”.
-
.format_number(number) ⇒ Object
Format a number with comma separators Example: 1234567 => “1,234,567”.
-
.format_percentage(decimal) ⇒ Object
Format a percentage with 1 decimal place Example: 0.1234 => “12.3%”.
Class Method Details
.format_currency(amount) ⇒ Object
Format a dollar amount with 2 decimal places Example: 1.234 => “$1.23”
18 19 20 21 22 |
# File 'lib/claude_usage/formatters.rb', line 18 def format_currency(amount) return '$0.00' if amount.nil? || amount.zero? format('$%.2f', amount) end |
.format_number(number) ⇒ Object
Format a number with comma separators Example: 1234567 => “1,234,567”
10 11 12 13 14 |
# File 'lib/claude_usage/formatters.rb', line 10 def format_number(number) return '0' if number.nil? || number.zero? number.to_s.reverse.gsub(/(\d{3})(?=\d)/, '\\1,').reverse end |
.format_percentage(decimal) ⇒ Object
Format a percentage with 1 decimal place Example: 0.1234 => “12.3%”
26 27 28 29 30 |
# File 'lib/claude_usage/formatters.rb', line 26 def format_percentage(decimal) return '0.0%' if decimal.nil? || decimal.zero? format('%.1f%%', decimal * 100) end |