Class: Stringento::Placeholder
- Inherits:
-
Object
- Object
- Stringento::Placeholder
- Defined in:
- lib/stringento/placeholder.rb
Overview
A placeholder is a to-be-resolved-and-formatted token within a string. A placeholder has a minimum one part and at maximum three parts (token::formatter:argument), for example:
-
first_name
-
first_name::capitalize
-
dob::date::mm-dd-yyyy
Constant Summary collapse
- SEPARATOR =
'::'
Instance Attribute Summary collapse
-
#arg ⇒ Object
readonly
Returns the value of attribute arg.
-
#formatter ⇒ Object
readonly
Returns the value of attribute formatter.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
-
#initialize(value) ⇒ Placeholder
constructor
A new instance of Placeholder.
Constructor Details
#initialize(value) ⇒ Placeholder
Returns a new instance of Placeholder.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/stringento/placeholder.rb', line 22 def initialize(value) @value = value.to_s parts = @value.split(SEPARATOR) count = parts.length raise ArgumentError, "Cannot be split: #{value}" if count.negative? || count > 3 @name = parts[0] || '' @formatter = parts[1] || '' @arg = parts[2] || '' freeze end |
Instance Attribute Details
#arg ⇒ Object (readonly)
Returns the value of attribute arg.
20 21 22 |
# File 'lib/stringento/placeholder.rb', line 20 def arg @arg end |
#formatter ⇒ Object (readonly)
Returns the value of attribute formatter.
20 21 22 |
# File 'lib/stringento/placeholder.rb', line 20 def formatter @formatter end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
20 21 22 |
# File 'lib/stringento/placeholder.rb', line 20 def name @name end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
20 21 22 |
# File 'lib/stringento/placeholder.rb', line 20 def value @value end |