Class: StringSplitter::Split
- Inherits:
-
Object
- Object
- StringSplitter::Split
- Defined in:
- lib/string_splitter/split.rb
Defined Under Namespace
Modules: Refinements
Instance Attribute Summary collapse
-
#captures ⇒ Object
readonly
Returns the value of attribute captures.
-
#count ⇒ Object
readonly
Returns the value of attribute count.
-
#index ⇒ Object
readonly
Returns the value of attribute index.
-
#lhs ⇒ Object
readonly
Returns the value of attribute lhs.
-
#position ⇒ Object
(also: #pos)
readonly
Returns the value of attribute position.
-
#rhs ⇒ Object
Returns the value of attribute rhs.
-
#separator ⇒ Object
readonly
Returns the value of attribute separator.
Instance Method Summary collapse
-
#initialize(captures:, lhs:, rhs:, separator:) ⇒ Split
constructor
A new instance of Split.
-
#rindex ⇒ Object
0-based index relative to the end of the array, e.g.
-
#rposition ⇒ Object
(also: #rpos)
1-based position relative to the end of the array, e.g.
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
#captures ⇒ Object (readonly)
Returns the value of attribute captures.
21 22 23 |
# File 'lib/string_splitter/split.rb', line 21 def captures @captures end |
#count ⇒ Object (readonly)
Returns the value of attribute count.
21 22 23 |
# File 'lib/string_splitter/split.rb', line 21 def count @count end |
#index ⇒ Object (readonly)
Returns the value of attribute index.
21 22 23 |
# File 'lib/string_splitter/split.rb', line 21 def index @index end |
#lhs ⇒ Object (readonly)
Returns the value of attribute lhs.
21 22 23 |
# File 'lib/string_splitter/split.rb', line 21 def lhs @lhs end |
#position ⇒ Object (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 |
#rhs ⇒ Object
Returns the value of attribute rhs.
21 22 23 |
# File 'lib/string_splitter/split.rb', line 21 def rhs @rhs end |
#separator ⇒ Object (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
#rindex ⇒ Object
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 |
#rposition ⇒ Object 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 |