Class: Squared::Common::JoinSet
- Inherits:
-
Set
- Object
- Set
- Squared::Common::JoinSet
- Defined in:
- lib/squared/common/class.rb
Instance Attribute Summary collapse
-
#delim ⇒ Object
readonly
Returns the value of attribute delim.
Class Method Summary collapse
Instance Method Summary collapse
- #done ⇒ Object
-
#initialize(data = [], delim: ' ') ⇒ JoinSet
constructor
A new instance of JoinSet.
- #last(val, pat) ⇒ Object
- #pass(&blk) ⇒ Object
- #temp(*args, &blk) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(data = [], delim: ' ') ⇒ JoinSet
Returns a new instance of JoinSet.
39 40 41 42 |
# File 'lib/squared/common/class.rb', line 39 def initialize(data = [], delim: ' ') super(data.compact) @delim = delim end |
Instance Attribute Details
#delim ⇒ Object (readonly)
Returns the value of attribute delim.
37 38 39 |
# File 'lib/squared/common/class.rb', line 37 def delim @delim end |
Class Method Details
.to_s ⇒ Object
33 34 35 |
# File 'lib/squared/common/class.rb', line 33 def self.to_s super[/[^:]+\z/, 0] end |
Instance Method Details
#done ⇒ Object
81 82 83 84 85 |
# File 'lib/squared/common/class.rb', line 81 def done ret = to_s clear ret end |
#last(val, pat) ⇒ Object
44 45 46 47 |
# File 'lib/squared/common/class.rb', line 44 def last(val, pat) (@last ||= []).push([val, pat, $1]) if val =~ pat self << val end |
#pass(&blk) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/squared/common/class.rb', line 49 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
74 75 76 77 78 79 |
# File 'lib/squared/common/class.rb', line 74 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
87 88 89 |
# File 'lib/squared/common/class.rb', line 87 def to_s pass.join(@delim) end |