Class: TheoryCollection

Inherits:
Object show all
Defined in:
lib/theory/theory_collection.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(theories) ⇒ TheoryCollection

Returns a new instance of TheoryCollection.



5
6
7
# File 'lib/theory/theory_collection.rb', line 5

def initialize(theories)
  @theories = theories
end

Instance Attribute Details

#theoriesObject (readonly)

Returns the value of attribute theories.



3
4
5
# File 'lib/theory/theory_collection.rb', line 3

def theories
  @theories
end

Instance Method Details

#actionsObject



50
51
52
# File 'lib/theory/theory_collection.rb', line 50

def actions
  @theories.select {|x| x.action != nil}.inject([]) {|total,theory| total << theory.action }
end

#componentsObject



54
55
56
# File 'lib/theory/theory_collection.rb', line 54

def components
  return dependents+results
end

#dependentsObject

Returns all the dependents within the theories



42
43
44
# File 'lib/theory/theory_collection.rb', line 42

def dependents
  @theories.inject([]) {|total,theory| total += theory.dependents }
end

#each_with_dependent_structure(structure) ⇒ Object



19
20
21
22
23
24
25
26
27
# File 'lib/theory/theory_collection.rb', line 19

def each_with_dependent_structure(structure)
  @theories.each do |t|
    t.dependents.each do |d|
      if d.same_structure?(structure)
        yield t, d
      end
    end
  end    
end

#each_with_result_structure(structure) ⇒ Object



9
10
11
12
13
14
15
16
17
# File 'lib/theory/theory_collection.rb', line 9

def each_with_result_structure(structure)
  @theories.each do |t|
    t.results.each do |r|
      if r.same_structure?(structure)
        yield t, r
      end
    end
  end
end

#resultsObject



46
47
48
# File 'lib/theory/theory_collection.rb', line 46

def results
  @theories.inject([]) {|total,theory| total += theory.results }
end

#same_structure_count(structure, approach) ⇒ Object

Returns the number of theories that have dependents or results that match the structure supplied.

Parameters:

  • approach

    Either :dependents or :results



34
35
36
37
38
# File 'lib/theory/theory_collection.rb', line 34

def same_structure_count(structure,approach)
  @theories.inject(0) do |total,theory|
    total += theory.send(approach).count {|x| x.same_structure?(structure)}
  end
end

#theory_variablesObject

Returns an array of all the uniq theory variables used.



59
60
61
# File 'lib/theory/theory_collection.rb', line 59

def theory_variables
  return @theories.inject([]) {|total,x| total += x.all_theory_variables}.uniq
end