Class: Text::Format::Number
- Inherits:
-
Object
- Object
- Text::Format::Number
- Defined in:
- lib/text/format/number.rb
Overview
Provides a numbering object that will produce numbers. Accepts three parameters for numbering that will control how the numbers are presented when given as #[](index).
:offset
-
The number to add to the index in order to produce the proper index. This is because #tag_text indexes from 0, not 1. This defaults to 1.
:postfix
-
The value that will be appended to the number presented by #[]. Defaults to
nil
. :prefix
-
The value that will be prepended to the number presented by #[]. Defaults to
nil
.
n1 = Text::Format::Number.new(:postfix => ".")
puts n1[0] # => "1."
puts n1[1] # => "2.
n2 = Text::Format::Number.new(:prefix => "2.")
puts n2[0] # => "2.1"
puts n2[1] # => "2.2"
n3 = Text::Format::Number.new(:offset => 3)
puts n3[0] # => "3"
puts n3[1] # => "4"
Instance Method Summary collapse
- #[](index) ⇒ Object
-
#initialize(options = {}) ⇒ Number
constructor
:yields self:.
Constructor Details
#initialize(options = {}) ⇒ Number
:yields self:
29 30 31 32 33 |
# File 'lib/text/format/number.rb', line 29 def initialize( = {}) #:yields self: @offset = [:offset].to_i || 1 @postfix = [:postfix] || nil @prefix = [:prefix] || nil end |
Instance Method Details
#[](index) ⇒ Object
25 26 27 |
# File 'lib/text/format/number.rb', line 25 def [](index) "#{@prefix}#{index + @offset}#{@postfix}" end |