Class: Cecil::Placeholder
- Inherits:
-
Struct
- Object
- Struct
- Cecil::Placeholder
- Defined in:
- lib/cecil/placeholder.rb
Overview
Represents the name and location of a placeholder in a string.
Instance Attribute Summary collapse
-
#ident ⇒ String
The name of this placeholder.
-
#offset_end ⇒ Integer
The offset where this placeholder ends in the string.
-
#offset_start ⇒ Integer
The offset where this placeholder starts in the string.
Instance Method Summary collapse
-
#range ⇒ Range(Integer)
Return the range that this placeholder occupies in the string.
-
#transform_key(member) ⇒ Placeholder
Create a new Placeholder with one member transformed by the given block.
-
#with(**kwargs) ⇒ Object
Mimicks Data#with, introduced in Ruby 3.2.
Instance Attribute Details
#ident ⇒ String
Returns the name of this placeholder. E.g. the ident
of ${my_field}
would be my_field
.
3 4 5 |
# File 'lib/cecil/placeholder.rb', line 3 def ident @ident end |
#offset_end ⇒ Integer
Returns the offset where this placeholder ends in the string. This number is usually taken from a Regexp match.
3 4 5 |
# File 'lib/cecil/placeholder.rb', line 3 def offset_end @offset_end end |
#offset_start ⇒ Integer
Returns the offset where this placeholder starts in the string. This number is usually taken from a Regexp match.
3 4 5 |
# File 'lib/cecil/placeholder.rb', line 3 def offset_start @offset_start end |
Instance Method Details
#range ⇒ Range(Integer)
Return the range that this placeholder occupies in the string
17 |
# File 'lib/cecil/placeholder.rb', line 17 def range = offset_start...offset_end |
#transform_key(member) ⇒ Placeholder
Create a new Cecil::Placeholder with one member transformed by the given block
29 |
# File 'lib/cecil/placeholder.rb', line 29 def transform_key(member) = with(**{ member => yield(self[member]) }) |
#with(**kwargs) ⇒ Object
Mimicks Data#with, introduced in Ruby 3.2
20 |
# File 'lib/cecil/placeholder.rb', line 20 def with(**kwargs) = self.class.new(*to_h.merge(kwargs).values_at(*members)) |