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.



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

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

Instance Attribute Details

#delimObject (readonly)

Returns the value of attribute delim.



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

def delim
  @delim
end

Class Method Details

.to_sObject



251
252
253
# File 'lib/squared/workspace/project/support/class.rb', line 251

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

Instance Method Details

#and(*args) ⇒ Object



292
293
294
295
# File 'lib/squared/workspace/project/support/class.rb', line 292

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

#doneObject



313
314
315
316
317
# File 'lib/squared/workspace/project/support/class.rb', line 313

def done
  ret = to_s
  clear
  ret
end

#last(val, pat) ⇒ Object



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

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

#or(*args) ⇒ Object



297
298
299
300
# File 'lib/squared/workspace/project/support/class.rb', line 297

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

#pass(&blk) ⇒ Object



267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
# File 'lib/squared/workspace/project/support/class.rb', line 267

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



306
307
308
309
310
311
# File 'lib/squared/workspace/project/support/class.rb', line 306

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



319
320
321
# File 'lib/squared/workspace/project/support/class.rb', line 319

def to_s
  pass.join(@delim)
end

#with(*args, &blk) ⇒ Object



302
303
304
# File 'lib/squared/workspace/project/support/class.rb', line 302

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