Class: Masamune::DataPlan::Set
- Inherits:
-
Set
- Object
- Set
- Masamune::DataPlan::Set
- Defined in:
- lib/masamune/data_plan/set.rb
Constant Summary collapse
- EMPTY =
new
Instance Attribute Summary collapse
-
#rule ⇒ Object
readonly
Returns the value of attribute rule.
Instance Method Summary collapse
- #actionable ⇒ Object
- #add(elem = nil) ⇒ Object
- #adjacent ⇒ Object
- #existing ⇒ Object
- #include?(elem = nil) ⇒ Boolean
- #incomplete ⇒ Object
-
#initialize(rule, enum = nil) ⇒ Set
constructor
A new instance of Set.
- #missing ⇒ Object
- #sources ⇒ Object
- #stale ⇒ Object
- #targets ⇒ Object
- #union(enum = nil) ⇒ Object
- #updateable ⇒ Object
-
#with_grain(grain) ⇒ Object
TODO: detect & warn or correct if coarser grain set is incomplete.
Constructor Details
#initialize(rule, enum = nil) ⇒ Set
Returns a new instance of Set.
30 31 32 33 |
# File 'lib/masamune/data_plan/set.rb', line 30 def initialize(rule, enum = nil) @rule = rule super convert_enum(enum) end |
Instance Attribute Details
#rule ⇒ Object (readonly)
Returns the value of attribute rule.
28 29 30 |
# File 'lib/masamune/data_plan/set.rb', line 28 def rule @rule end |
Instance Method Details
#actionable ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/masamune/data_plan/set.rb', line 89 def actionable return Masamune::DataPlan::Set::EMPTY if empty? || @rule.for_sources? return self.class.new(rule, to_enum(__method__)) unless block_given? set = Set.new missing do |target| yield target if set.add?(target) end incomplete do |target| yield target if set.add?(target) end stale do |target| yield target if set.add?(target) end end |
#add(elem = nil) ⇒ Object
39 40 41 |
# File 'lib/masamune/data_plan/set.rb', line 39 def add(elem = nil) super convert_elem(elem) end |
#adjacent ⇒ Object
63 64 65 66 67 68 69 70 |
# File 'lib/masamune/data_plan/set.rb', line 63 def adjacent return self.class.new(rule, to_enum(__method__)) unless block_given? each do |elem| @rule.adjacent_matches(elem).each do |adj_elem| yield adj_elem end end end |
#existing ⇒ Object
54 55 56 57 58 59 60 61 |
# File 'lib/masamune/data_plan/set.rb', line 54 def existing return self.class.new(rule, to_enum(__method__)) unless block_given? each do |elem| elem.explode.each do |new_elem| yield new_elem end end end |
#include?(elem = nil) ⇒ Boolean
43 44 45 |
# File 'lib/masamune/data_plan/set.rb', line 43 def include?(elem = nil) super convert_elem(elem) end |
#incomplete ⇒ Object
80 81 82 83 84 85 86 87 |
# File 'lib/masamune/data_plan/set.rb', line 80 def incomplete return Masamune::DataPlan::Set::EMPTY if empty? || @rule.for_sources? return self.class.new(rule, to_enum(__method__)) unless block_given? set = Set.new each do |target| yield target unless target.complete? || !set.add?(target) end end |
#missing ⇒ Object
47 48 49 50 51 52 |
# File 'lib/masamune/data_plan/set.rb', line 47 def missing return self.class.new(rule, to_enum(__method__)) unless block_given? each do |elem| yield elem if elem.explode.none? end end |
#sources ⇒ Object
133 134 135 136 137 138 139 140 141 |
# File 'lib/masamune/data_plan/set.rb', line 133 def sources return Masamune::DataPlan::Set::EMPTY if empty? || @rule.for_sources? return self.class.new(first.sources.rule, to_enum(__method__)) unless block_given? each do |elem| elem.sources do |source| yield source end end end |
#stale ⇒ Object
72 73 74 75 76 77 78 |
# File 'lib/masamune/data_plan/set.rb', line 72 def stale return Masamune::DataPlan::Set::EMPTY if empty? || @rule.for_sources? return self.class.new(rule, to_enum(__method__)) unless block_given? each do |target| yield target if target.sources.existing.any? { |source| target_stale?(source, target) } end end |
#targets ⇒ Object
123 124 125 126 127 128 129 130 131 |
# File 'lib/masamune/data_plan/set.rb', line 123 def targets return Masamune::DataPlan::Set::EMPTY if empty? || @rule.for_targets? return self.class.new(first.targets.rule, to_enum(__method__)) unless block_given? each do |elem| elem.targets do |target| yield target end end end |
#union(enum = nil) ⇒ Object
35 36 37 |
# File 'lib/masamune/data_plan/set.rb', line 35 def union(enum = nil) super(convert_enum(enum) || EMPTY) end |
#updateable ⇒ Object
104 105 106 107 108 109 110 111 |
# File 'lib/masamune/data_plan/set.rb', line 104 def updateable return Masamune::DataPlan::Set::EMPTY if empty? || @rule.for_sources? return self.class.new(rule, to_enum(__method__)) unless block_given? set = Set.new actionable do |target| yield target if set.add?(target) && target.sources.existing.any? end end |
#with_grain(grain) ⇒ Object
TODO: detect & warn or correct if coarser grain set is incomplete
114 115 116 117 118 119 120 121 |
# File 'lib/masamune/data_plan/set.rb', line 114 def with_grain(grain) return self.class.new(rule.round(grain), to_enum(:with_grain, grain)) unless block_given? seen = Set.new each do |elem| granular_elem = elem.round(grain) yield granular_elem if seen.add?(granular_elem) end end |