Module: Sinatra::Numeric

Defined in:
lib/sinatra/support/numeric.rb

Overview

Provides numeric helpers.

require 'sinatra/support/numeric'

class Main < Sinatra::Base
  register Sinatra::Numeric
end

Helpers

This plugin provides the following helpers:

currency - Formats a string as a currency.

<%= currency(100) %>
<!-- $100 -->

percentage - Formats a number as a percentage.

<%= percentage(100) %>
<!-- 100.00% -->

Settings

You may change the settings like so:

Main.configure do |m|
  m.set :default_currency_unit, '$'
  m.set :default_currency_precision, 2
  m.set :default_currency_separator, ','
end

Defined Under Namespace

Modules: Helpers

Class Method Summary collapse

Class Method Details

.registered(app) ⇒ Object



34
35
36
37
38
39
40
# File 'lib/sinatra/support/numeric.rb', line 34

def self.registered(app)
  app.set :default_currency_unit, '$'
  app.set :default_currency_precision, 2
  app.set :default_currency_separator, ','

  app.helpers Helpers
end