Class: Stringento::Placeholder

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(value) ⇒ Placeholder

Returns a new instance of Placeholder.

Raises:

  • (ArgumentError)


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

#argObject (readonly)

Returns the value of attribute arg.



20
21
22
# File 'lib/stringento/placeholder.rb', line 20

def arg
  @arg
end

#formatterObject (readonly)

Returns the value of attribute formatter.



20
21
22
# File 'lib/stringento/placeholder.rb', line 20

def formatter
  @formatter
end

#nameObject (readonly)

Returns the value of attribute name.



20
21
22
# File 'lib/stringento/placeholder.rb', line 20

def name
  @name
end

#valueObject (readonly)

Returns the value of attribute value.



20
21
22
# File 'lib/stringento/placeholder.rb', line 20

def value
  @value
end