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
19
20
21
|
# File 'lib/ppl/format/custom.rb', line 19
def initialize(format = nil)
@format = format
end
|
Instance Attribute Details
Returns the value of attribute format.
3
4
5
|
# File 'lib/ppl/format/custom.rb', line 3
def format
@format
end
|
Returns the value of attribute preset_formats.
4
5
6
|
# File 'lib/ppl/format/custom.rb', line 4
def preset_formats
@preset_formats
end
|
Class Method Details
6
7
8
9
|
# File 'lib/ppl/format/custom.rb', line 6
def self.format(symbol, &block)
@format_blocks ||= {}
@format_blocks[symbol] = block
end
|
.process(key, object) ⇒ Object
11
12
13
14
15
16
17
|
# File 'lib/ppl/format/custom.rb', line 11
def self.process(key, object)
if @format_blocks[key]
@format_blocks[key][object]
else
key
end
end
|
Instance Method Details
#process(object) ⇒ Object
23
24
25
26
27
|
# File 'lib/ppl/format/custom.rb', line 23
def process(object)
@object = object
string_pieces = @format.scan(/[^%]+|%-?\d*./)
string_pieces.map(&method(:process_piece)).join
end
|
#use_preset(format_name) ⇒ Object
29
30
31
|
# File 'lib/ppl/format/custom.rb', line 29
def use_preset(format_name)
@format = @preset_formats[format_name]
end
|