Class: Hydrangea::GraphPartition

Inherits:
Object
  • Object
show all
Defined in:
lib/hydrangea/graph_partition.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(state_arg) ⇒ GraphPartition

Returns a new instance of GraphPartition.



12
13
14
15
16
17
18
# File 'lib/hydrangea/graph_partition.rb', line 12

def initialize(state_arg)
  @lookup = ALL if state_arg == :all || state_arg == 'all'
  @lookup ||= Array(state_arg).reduce(Set.new) do |set,state|
    invalid_state_arg(state) unless ALL.include?(state)
    set << state
  end
end

Class Method Details

.[](state_arg) ⇒ Object



5
6
7
8
# File 'lib/hydrangea/graph_partition.rb', line 5

def self.[](state_arg)
  @instances ||= {}
  @instances[state_arg] ||= new(state_arg)
end

Instance Method Details

#invalid_state_arg(arg) ⇒ Object

Raises:

  • (ArgumentError)


28
29
30
# File 'lib/hydrangea/graph_partition.rb', line 28

def invalid_state_arg(arg)
  raise ArgumentError, "not a valid graph state: #{arg.inspect}"
end

#reject(graph) ⇒ Object



24
25
26
# File 'lib/hydrangea/graph_partition.rb', line 24

def reject(graph)
  graph.each.reject{ |node| @lookup.include?(node.state) }
end

#select(graph) ⇒ Object



20
21
22
# File 'lib/hydrangea/graph_partition.rb', line 20

def select(graph)
  graph.each.select{ |node| @lookup.include?(node.state) }
end