Class: StringSplitter::Split

Inherits:
Object
  • Object
show all
Defined in:
lib/string_splitter/split.rb

Defined Under Namespace

Modules: Refinements

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(captures:, lhs:, rhs:, separator:) ⇒ Split

Returns a new instance of Split.



26
27
28
29
30
31
# File 'lib/string_splitter/split.rb', line 26

def initialize(captures:, lhs:, rhs:, separator:)
  @captures = captures
  @lhs = lhs
  @rhs = rhs
  @separator = separator
end

Instance Attribute Details

#capturesObject (readonly)

Returns the value of attribute captures.



21
22
23
# File 'lib/string_splitter/split.rb', line 21

def captures
  @captures
end

#countObject (readonly)

Returns the value of attribute count.



21
22
23
# File 'lib/string_splitter/split.rb', line 21

def count
  @count
end

#indexObject (readonly)

Returns the value of attribute index.



21
22
23
# File 'lib/string_splitter/split.rb', line 21

def index
  @index
end

#lhsObject (readonly)

Returns the value of attribute lhs.



21
22
23
# File 'lib/string_splitter/split.rb', line 21

def lhs
  @lhs
end

#positionObject (readonly) Also known as: pos

Returns the value of attribute position.



21
22
23
# File 'lib/string_splitter/split.rb', line 21

def position
  @position
end

#rhsObject

Returns the value of attribute rhs.



21
22
23
# File 'lib/string_splitter/split.rb', line 21

def rhs
  @rhs
end

#separatorObject (readonly)

Returns the value of attribute separator.



21
22
23
# File 'lib/string_splitter/split.rb', line 21

def separator
  @separator
end

Instance Method Details

#rindexObject

0-based index relative to the end of the array, e.g. for 5 items:

index | rindex
------|-------
  0   |   4
  1   |   3
  2   |   2
  3   |   1
  4   |   0


42
43
44
# File 'lib/string_splitter/split.rb', line 42

def rindex
  @count - @position
end

#rpositionObject Also known as: rpos

1-based position relative to the end of the array, e.g. for 5 items:

 position | rposition
----------|----------
    1     |    5
    2     |    4
    3     |    3
    4     |    2
    5     |    1


55
56
57
# File 'lib/string_splitter/split.rb', line 55

def rposition
  @count + 1 - @position
end