Class: Squared::Workspace::Project::Support::JoinSet

Inherits:
Set
  • Object
show all
Defined in:
lib/squared/workspace/project/support/class.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data = [], delim: ' ') ⇒ JoinSet

Returns a new instance of JoinSet.



221
222
223
224
# File 'lib/squared/workspace/project/support/class.rb', line 221

def initialize(data = [], delim: ' ')
  super(data.compact)
  @delim = delim
end

Instance Attribute Details

#delimObject (readonly)

Returns the value of attribute delim.



219
220
221
# File 'lib/squared/workspace/project/support/class.rb', line 219

def delim
  @delim
end

Class Method Details

.to_sObject



215
216
217
# File 'lib/squared/workspace/project/support/class.rb', line 215

def self.to_s
  super[/[^:]+\z/, 0]
end

Instance Method Details

#and(*args) ⇒ Object



256
257
258
259
# File 'lib/squared/workspace/project/support/class.rb', line 256

def and(*args)
  self << '&&'
  merge args
end

#doneObject



277
278
279
280
281
# File 'lib/squared/workspace/project/support/class.rb', line 277

def done
  ret = to_s
  clear
  ret
end

#last(val, pat) ⇒ Object



226
227
228
229
# File 'lib/squared/workspace/project/support/class.rb', line 226

def last(val, pat)
  (@last ||= []).append([val, pat, $1]) if val =~ pat
  self << val
end

#or(*args) ⇒ Object



261
262
263
264
# File 'lib/squared/workspace/project/support/class.rb', line 261

def or(*args)
  self << '||'
  merge args
end

#pass(&blk) ⇒ Object



231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
# File 'lib/squared/workspace/project/support/class.rb', line 231

def pass(&blk)
  ret = to_a.map!(&:to_s).reject(&:empty?)
  @last&.each do |val, pat, key|
    i = []
    j = nil
    ret.each_with_index do |opt, index|
      if opt == val
        j = index
      elsif j && opt[pat, 1] == key
        i << index
      end
    end
    next unless j && !i.empty?

    val = ret[j]
    cur = j
    i.each do |k|
      ret[cur] = ret[k]
      cur = k
    end
    ret[i.last] = val
  end
  block_given? ? ret.reject(&blk) : ret
end

#temp(*args, &blk) ⇒ Object



270
271
272
273
274
275
# File 'lib/squared/workspace/project/support/class.rb', line 270

def temp(*args, &blk)
  args.compact!
  ret = pass(&blk)
  ret = Set.new(ret.concat(args)).to_a unless args.empty?
  ret.join(@delim)
end

#to_sObject



283
284
285
# File 'lib/squared/workspace/project/support/class.rb', line 283

def to_s
  pass.join(@delim)
end

#with(*args, &blk) ⇒ Object



266
267
268
# File 'lib/squared/workspace/project/support/class.rb', line 266

def with(*args, &blk)
  temp('&&', *args, &blk)
end