Module: DTK::DSL::Template::Parsing::ParentKey::Index
- Defined in:
- lib/dsl/template/parsing/parent_key.rb
Constant Summary collapse
- LEFT_DELIM =
'['
- RIGHT_DELIM =
']'
Class Method Summary collapse
-
.parse_segment(key_seqment) ⇒ Object
returns [type, index] where index can be nil.
- .with_delims(index) ⇒ Object
Class Method Details
.parse_segment(key_seqment) ⇒ Object
returns [type, index] where index can be nil
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/dsl/template/parsing/parent_key.rb', line 54 def self.parse_segment(key_seqment) type = index = nil split_on_left = key_seqment.split(LEFT_DELIM) if split_on_left.size == 1 type = key_seqment else type = split_on_left.shift # find index # being robust if index has index symbols in it by looking for leftmost left deleim and rightmost right delim rest = split_on_left.join(LEFT_DELIM) split_on_right = rest.split(RIGHT_DELIM) if split_on_right.size == 1 index = split_on_right.first else split_on_right.pop # get rid of end index = split_on_right.join(RIGHT_DELIM) end end [type, index] end |
.with_delims(index) ⇒ Object
49 50 51 |
# File 'lib/dsl/template/parsing/parent_key.rb', line 49 def self.with_delims(index) "#{LEFT_DELIM}#{index}#{RIGHT_DELIM}" end |