Class: Squared::Workspace::Project::Support::JoinSet
- Inherits:
-
Set
- Object
- Set
- Squared::Workspace::Project::Support::JoinSet
- Defined in:
- lib/squared/workspace/project/support/class.rb
Instance Attribute Summary collapse
-
#delim ⇒ Object
readonly
Returns the value of attribute delim.
Class Method Summary collapse
Instance Method Summary collapse
- #and(*args) ⇒ Object
- #done ⇒ Object
-
#initialize(data = [], delim: ' ') ⇒ JoinSet
constructor
A new instance of JoinSet.
- #last(val, pat) ⇒ Object
- #or(*args) ⇒ Object
- #pass(&blk) ⇒ Object
- #temp(*args, &blk) ⇒ Object
- #to_s ⇒ Object
- #with(*args, &blk) ⇒ Object
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
#delim ⇒ Object (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_s ⇒ Object
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 |
#done ⇒ Object
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_s ⇒ Object
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 |