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.
-
#extras ⇒ Object
readonly
Returns the value of attribute extras.
-
#multiple ⇒ Object
Returns the value of attribute multiple.
Class Method Summary collapse
Instance Method Summary collapse
- #<<(obj) ⇒ Object (also: #add, #add?, #push)
- #and(*args) ⇒ Object
- #compact ⇒ Object
- #done ⇒ Object
- #include?(obj) ⇒ Boolean (also: #member?)
-
#initialize(data = [], delim: ' ', partition: '--', uniq: /\A--?[^=\s-]/, multiple: []) ⇒ JoinSet
constructor
A new instance of JoinSet.
- #insert(*args) ⇒ Object
- #last(val, pat) ⇒ Object
- #merge(enum) ⇒ Object (also: #concat)
- #multiple?(val) ⇒ Boolean
- #or(*args) ⇒ Object
- #pass(&blk) ⇒ Object
- #size ⇒ Object
- #slice(*args) ⇒ Object
- #slice!(*args) ⇒ Object
- #temp(*args, &blk) ⇒ Object
- #to_a ⇒ Object
- #to_ary ⇒ Object
- #to_enum(*args) ⇒ Object
- #to_json(*args) ⇒ Object
- #to_s ⇒ Object
- #to_yaml(*args) ⇒ Object
- #with(*args, &blk) ⇒ Object
Constructor Details
#initialize(data = [], delim: ' ', partition: '--', uniq: /\A--?[^=\s-]/, multiple: []) ⇒ JoinSet
Returns a new instance of JoinSet.
18 19 20 21 22 23 24 25 |
# File 'lib/squared/workspace/project/support/class.rb', line 18 def initialize(data = [], delim: ' ', partition: '--', uniq: /\A--?[^=\s-]/, multiple: []) @delim = delim @partition = partition @uniq = uniq @multiple = multiple @extras = [] super(data.compact) end |
Instance Attribute Details
#delim ⇒ Object (readonly)
Returns the value of attribute delim.
16 17 18 |
# File 'lib/squared/workspace/project/support/class.rb', line 16 def delim @delim end |
#extras ⇒ Object (readonly)
Returns the value of attribute extras.
16 17 18 |
# File 'lib/squared/workspace/project/support/class.rb', line 16 def extras @extras end |
#multiple ⇒ Object
Returns the value of attribute multiple.
16 17 18 |
# File 'lib/squared/workspace/project/support/class.rb', line 16 def multiple @multiple end |
Class Method Details
.to_s ⇒ Object
10 11 12 |
# File 'lib/squared/workspace/project/support/class.rb', line 10 def self.to_s super[/[^:]+\z/, 0] end |
Instance Method Details
#<<(obj) ⇒ Object Also known as: add, add?, push
137 138 139 140 141 142 143 144 145 146 |
# File 'lib/squared/workspace/project/support/class.rb', line 137 def <<(obj) unless obj.nil? return super if extras.empty? && !extras?(obj) unless !extras.include?(@partition) && include?(obj) && @uniq.match?(s = obj.to_s) && !multiple?(s) extras << obj end end self end |
#and(*args) ⇒ Object
92 93 94 95 |
# File 'lib/squared/workspace/project/support/class.rb', line 92 def and(*args) self << '&&' merge args end |
#compact ⇒ Object
55 56 57 |
# File 'lib/squared/workspace/project/support/class.rb', line 55 def compact dump to_ary end |
#done ⇒ Object
113 114 115 116 117 |
# File 'lib/squared/workspace/project/support/class.rb', line 113 def done ret = to_s clear ret end |
#include?(obj) ⇒ Boolean Also known as: member?
152 153 154 155 156 157 |
# File 'lib/squared/workspace/project/support/class.rb', line 152 def include?(obj) return true if super return extras.include?(obj) unless (n = extras.index(@partition)) extras[0..n].include?(obj) end |
#insert(*args) ⇒ Object
40 41 42 |
# File 'lib/squared/workspace/project/support/class.rb', line 40 def insert(*args) replace Set.new(compact.insert(*args)) end |
#last(val, pat) ⇒ Object
59 60 61 62 |
# File 'lib/squared/workspace/project/support/class.rb', line 59 def last(val, pat) (@last ||= []).push([val, pat, $1]) if val =~ pat self << val end |
#merge(enum) ⇒ Object Also known as: concat
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/squared/workspace/project/support/class.rb', line 119 def merge(enum) if !extras.empty? extras.concat(enum.to_a) self elsif (n = enum.find_index { |val| extras?(val) }) data = enum.to_a extras.concat(if n == 0 data else super(data[0, n]) data[n..-1] end) self else super end end |
#multiple?(val) ⇒ Boolean
159 160 161 |
# File 'lib/squared/workspace/project/support/class.rb', line 159 def multiple?(val) multiple.any? { |obj| obj.is_a?(Regexp) ? obj.match?(val) : obj == val } end |
#or(*args) ⇒ Object
97 98 99 100 |
# File 'lib/squared/workspace/project/support/class.rb', line 97 def or(*args) self << '||' merge args end |
#pass(&blk) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/squared/workspace/project/support/class.rb', line 64 def pass(&blk) ret = compact @last&.each do |val, pat, key| items = [] index = nil ret.each_with_index do |opt, i| if opt == val index = i elsif index && opt[pat, 1] == key items << i end end next unless index && !items.empty? val = ret[index] cur = index items.each do |k| ret[cur] = ret[k] cur = k end ret[items.last] = val end ret.concat(dump(extras)) unless extras.empty? return ret unless block_given? ret.reject(&blk) end |
#size ⇒ Object
148 149 150 |
# File 'lib/squared/workspace/project/support/class.rb', line 148 def size super + extras.size end |
#slice(*args) ⇒ Object
44 45 46 |
# File 'lib/squared/workspace/project/support/class.rb', line 44 def slice(*args) compact.slice(*args) end |
#slice!(*args) ⇒ Object
48 49 50 51 52 53 |
# File 'lib/squared/workspace/project/support/class.rb', line 48 def slice!(*args) data = compact ret = data.slice!(*args) replace Set.new(data) ret end |
#temp(*args, &blk) ⇒ Object
106 107 108 109 110 111 |
# File 'lib/squared/workspace/project/support/class.rb', line 106 def temp(*args, &blk) args.compact! pass(&blk) .concat(args) .join(@delim) end |
#to_a ⇒ Object
163 164 165 |
# File 'lib/squared/workspace/project/support/class.rb', line 163 def to_a pass end |
#to_ary ⇒ Object
14 |
# File 'lib/squared/workspace/project/support/class.rb', line 14 alias to_ary to_a |
#to_enum(*args) ⇒ Object
171 172 173 |
# File 'lib/squared/workspace/project/support/class.rb', line 171 def to_enum(*args) to_a.to_enum(*args) end |
#to_json(*args) ⇒ Object
175 176 177 |
# File 'lib/squared/workspace/project/support/class.rb', line 175 def to_json(*args) to_a.to_json(*args) end |
#to_s ⇒ Object
167 168 169 |
# File 'lib/squared/workspace/project/support/class.rb', line 167 def to_s to_a.join(@delim) end |
#to_yaml(*args) ⇒ Object
179 180 181 |
# File 'lib/squared/workspace/project/support/class.rb', line 179 def to_yaml(*args) to_a.to_yaml(*args) end |
#with(*args, &blk) ⇒ Object
102 103 104 |
# File 'lib/squared/workspace/project/support/class.rb', line 102 def with(*args, &blk) temp('&&', *args, &blk) end |