Class: Ppl::Format::Custom
- Inherits:
-
Object
- Object
- Ppl::Format::Custom
show all
- Defined in:
- lib/ppl/format/custom.rb
Defined Under Namespace
Classes: Contact, EmailAddress, PhoneNumber
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(format = nil) ⇒ Custom
20
21
22
|
# File 'lib/ppl/format/custom.rb', line 20
def initialize(format = nil)
@format = format
end
|
Instance Attribute Details
Returns the value of attribute format.
4
5
6
|
# File 'lib/ppl/format/custom.rb', line 4
def format
@format
end
|
Returns the value of attribute preset_formats.
5
6
7
|
# File 'lib/ppl/format/custom.rb', line 5
def preset_formats
@preset_formats
end
|
Class Method Details
7
8
9
10
|
# File 'lib/ppl/format/custom.rb', line 7
def self.format(symbol, &block)
@format_blocks ||= {}
@format_blocks[symbol] = block
end
|
.process(key, object) ⇒ Object
12
13
14
15
16
17
18
|
# File 'lib/ppl/format/custom.rb', line 12
def self.process(key, object)
if @format_blocks[key]
@format_blocks[key][object]
else
key
end
end
|
Instance Method Details
#process(object) ⇒ Object
24
25
26
27
28
|
# File 'lib/ppl/format/custom.rb', line 24
def process(object)
@object = object
string_pieces = @format.scan(/[^%]+|%-?\d*./)
string_pieces.map(&method(:process_piece)).join
end
|
#use_preset(format_name) ⇒ Object
30
31
32
|
# File 'lib/ppl/format/custom.rb', line 30
def use_preset(format_name)
@format = @preset_formats[format_name]
end
|