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.



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

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

Instance Attribute Details

#diffsObject (readonly)

Returns the value of attribute diffs.



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

def diffs
  @diffs
end

#stringObject (readonly)

Returns the value of attribute string.



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

def string
  @string
end

Instance Method Details

#changed?Boolean

Returns:

  • (Boolean)


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

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

#clearObject



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

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

#push(diff) ⇒ Object



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

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

#resetObject



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

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