Class: Suffix

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/adlint/prelude.rb

Direct Known Subclasses

LeftSuffix, RightSuffix

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(owner, idx) ⇒ Suffix

Returns a new instance of Suffix.



218
219
220
221
# File 'lib/adlint/prelude.rb', line 218

def initialize(owner, idx)
  @owner = owner
  @index = idx
end

Class Method Details

.of(str) ⇒ Object



214
215
216
# File 'lib/adlint/prelude.rb', line 214

def self.of(str)
  str.length.times.map { |idx| new(str, idx) }
end

Instance Method Details

#<=>(rhs) ⇒ Object



244
245
246
# File 'lib/adlint/prelude.rb', line 244

def <=>(rhs)
  self.to_s <=> rhs.to_s
end

#common_prefix_length(rhs) ⇒ Object



236
237
238
# File 'lib/adlint/prelude.rb', line 236

def common_prefix_length(rhs)
  to_s.chars.zip(rhs.to_s.chars).take_while { |lch, rch| lch == rch }.size
end

#lhs?Boolean

Returns:

  • (Boolean)


224
225
226
# File 'lib/adlint/prelude.rb', line 224

def lhs?
  subclass_responsibility
end

#prefix(len) ⇒ Object



240
241
242
# File 'lib/adlint/prelude.rb', line 240

def prefix(len)
  Substring.new(@owner, @index, len)
end

#rhs?Boolean

Returns:

  • (Boolean)


228
229
230
# File 'lib/adlint/prelude.rb', line 228

def rhs?
  !lhs?
end

#same_owner?(rhs) ⇒ Boolean

Returns:

  • (Boolean)


232
233
234
# File 'lib/adlint/prelude.rb', line 232

def same_owner?(rhs)
  @owner.equal?(rhs.owner)
end

#to_sObject



248
249
250
# File 'lib/adlint/prelude.rb', line 248

def to_s
  @owner.slice(@index..-1)
end