Class: Deflating

Inherits:
Object
  • Object
show all
Defined in:
lib/rantly/shrinks.rb

Overview

Array where the elements that can't be shrunk are removed

Instance Method Summary collapse

Constructor Details

#initialize(a) ⇒ Deflating

Returns a new instance of Deflating


113
114
115
116
# File 'lib/rantly/shrinks.rb', line 113

def initialize(a)
  @array = a
  @position = a.size - 1
end

Instance Method Details

#[](i) ⇒ Object


118
119
120
# File 'lib/rantly/shrinks.rb', line 118

def [](i)
  @array[i]
end

#[]=(i, value) ⇒ Object


122
123
124
# File 'lib/rantly/shrinks.rb', line 122

def []=(i, value)
  @array[i] = value
end

#arrayObject


146
147
148
# File 'lib/rantly/shrinks.rb', line 146

def array
  return @array
end

#each(&block) ⇒ Object


142
143
144
# File 'lib/rantly/shrinks.rb', line 142

def each(&block)
  @array.each(&block)
end

#inspectObject


138
139
140
# File 'lib/rantly/shrinks.rb', line 138

def inspect
  self.to_s
end

#lengthObject


126
127
128
# File 'lib/rantly/shrinks.rb', line 126

def length
  @array.length
end

#retry?Boolean

Returns:

  • (Boolean)

164
165
166
# File 'lib/rantly/shrinks.rb', line 164

def retry?
  @position >= 0
end

#shrinkObject


150
151
152
153
154
155
156
157
158
159
160
161
162
# File 'lib/rantly/shrinks.rb', line 150

def shrink
  shrunk = @array.dup
  if @position >= 0
    e = @array.at(@position)
    if e.respond_to?(:shrinkable?) && e.shrinkable?
      shrunk[@position] = e.shrink
    else
      shrunk.delete_at(@position)
    end
    @position -= 1
  end
  return Deflating.new(shrunk)
end

#shrinkable?Boolean

Returns:

  • (Boolean)

168
169
170
# File 'lib/rantly/shrinks.rb', line 168

def shrinkable?
  !@array.empty?
end

#sizeObject


130
131
132
# File 'lib/rantly/shrinks.rb', line 130

def size
  self.length
end

#to_sObject


134
135
136
# File 'lib/rantly/shrinks.rb', line 134

def to_s
  @array.to_s.insert(1, "D ")
end