Class: SubDiff::Collection

Inherits:
SimpleDelegator
  • Object
show all
Extended by:
Forwardable
Includes:
Enumerable
Defined in:
lib/sub_diff/collection.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(string) ⇒ Collection

Returns a new instance of Collection.



10
11
12
13
14
# File 'lib/sub_diff/collection.rb', line 10

def initialize(string)
  @string = string
  @diffs = []
  super(string)
end

Instance Attribute Details

#diffsObject (readonly)

Returns the value of attribute diffs.



8
9
10
# File 'lib/sub_diff/collection.rb', line 8

def diffs
  @diffs
end

#stringObject (readonly)

Returns the value of attribute string.



8
9
10
# File 'lib/sub_diff/collection.rb', line 8

def string
  @string
end

Instance Method Details

#changed?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/sub_diff/collection.rb', line 16

def changed?
  diffs.any?(&:changed?)
end

#clearObject



20
21
22
23
24
# File 'lib/sub_diff/collection.rb', line 20

def clear
  diffs.clear
  __setobj__('')
  self
end

#push(diff) ⇒ Object



26
27
28
29
30
31
# File 'lib/sub_diff/collection.rb', line 26

def push(diff)
  unless diff.empty?
    diffs << diff
    __setobj__(diffs.join)
  end
end

#resetObject



33
34
35
36
37
38
# File 'lib/sub_diff/collection.rb', line 33

def reset
  clear
  __setobj__(string)
  yield if block_given?
  self
end