Class: FuzzyLogic::Collection

Inherits:
Object
  • Object
show all
Defined in:
lib/fuzzy-logic/collection.rb

Instance Method Summary collapse

Constructor Details

#initialize(name, &test) ⇒ Collection

Returns a new instance of Collection.



7
8
9
10
11
12
# File 'lib/fuzzy-logic/collection.rb', line 7

def initialize(name, &test)
  @name = name
  # a test for inputvariables (returns true/false)
  @test = test
  @sets = {}
end

Instance Method Details

#[](fuzzysetname) ⇒ Object



23
24
25
# File 'lib/fuzzy-logic/collection.rb', line 23

def [](fuzzysetname)
  @sets[fuzzysetname.to_sym]
end

#[]=(fuzzysetname, fuzzyset) ⇒ Object

Raises:

  • (ArgumentError)


18
19
20
21
# File 'lib/fuzzy-logic/collection.rb', line 18

def []=(fuzzysetname, fuzzyset)
  raise ArgumentError, "Secound argument should be a Fuzzy-Set" unless fuzzyset.is_a?Set
  @sets[fuzzysetname.to_sym] = fuzzyset
end

#get(n, all = false) ⇒ Object

Raises:

  • (TypeError)


27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/fuzzy-logic/collection.rb', line 27

def get(n, all=false)
  raise TypeError, "Test of Fuzzy-Collection is not valid" unless [true, false].include? @test.call(n)
  raise ArgumentError, "Argument is not valid" unless @test.call(n)
  sets_output = {}
  @sets.each { |name, fset|
    x = fset.get(n)
    if x != 0 or all then
      sets_output[name] = x
    end
  }
  sets_output
end

#lengthObject



14
15
16
# File 'lib/fuzzy-logic/collection.rb', line 14

def length
  @sets.count
end