Class: Namo::Formulae
Instance Method Summary
collapse
Methods included from Enumerable
#drop, #drop_while, #first, #group_by, #last, #partition, #select, #sort_by, #take, #take_while, #uniq
Instance Method Details
#==(other) ⇒ Object
88
89
90
|
# File 'lib/Namo/Formulae.rb', line 88
def ==(other)
other.is_a?(Formulae) && keys.sort == other.keys.sort
end
|
#[](name) ⇒ Object
8
9
10
|
# File 'lib/Namo/Formulae.rb', line 8
def [](name)
@store[name]
end
|
#[]=(name, callable) ⇒ Object
12
13
14
|
# File 'lib/Namo/Formulae.rb', line 12
def []=(name, callable)
@store[name] = callable
end
|
#attach(modul) ⇒ Object
Also known as:
<<
16
17
18
19
20
|
# File 'lib/Namo/Formulae.rb', line 16
def attach(modul)
raise_unless_formulary(modul)
modul.public_instance_methods(false).each{|name| bind(name, modul)}
self
end
|
#delete(name) ⇒ Object
68
69
70
|
# File 'lib/Namo/Formulae.rb', line 68
def delete(name)
@store.delete(name)
end
|
#derive(name, row, namo, *arguments) ⇒ Object
36
37
38
39
40
41
42
43
44
|
# File 'lib/Namo/Formulae.rb', line 36
def derive(name, row, namo, *arguments)
formula = self[name]
if collection_scoped?(name)
raise_unless_namo_context(name, namo)
formula.call(row, namo, *arguments)
else
formula.call(row)
end
end
|
#detach(constituent) ⇒ Object
23
24
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/Namo/Formulae.rb', line 23
def detach(constituent)
case constituent
when Symbol
@store.delete(constituent)
when Module
raise_unless_formulary(constituent)
constituent.public_instance_methods(false).each{|name| @store.delete(name)}
else
raise TypeError, "can't detach #{constituent.class} from a Formulae; expected a Symbol or a Module (formulary)"
end
self
end
|
#dup ⇒ Object
80
81
82
|
# File 'lib/Namo/Formulae.rb', line 80
def dup
self.class.new(@store.dup)
end
|
#each(&block) ⇒ Object
63
64
65
66
|
# File 'lib/Namo/Formulae.rb', line 63
def each(&block)
return enum_for(:each) unless block_given?
@store.each(&block)
end
|
#empty? ⇒ Boolean
59
60
61
|
# File 'lib/Namo/Formulae.rb', line 59
def empty?
@store.empty?
end
|
#eql?(other) ⇒ Boolean
92
93
94
|
# File 'lib/Namo/Formulae.rb', line 92
def eql?(other)
self == other
end
|
#hash ⇒ Object
96
97
98
|
# File 'lib/Namo/Formulae.rb', line 96
def hash
keys.sort.hash
end
|
#key?(name) ⇒ Boolean
55
56
57
|
# File 'lib/Namo/Formulae.rb', line 55
def key?(name)
@store.key?(name)
end
|
#keys ⇒ Object
51
52
53
|
# File 'lib/Namo/Formulae.rb', line 51
def keys
@store.keys
end
|
#merge(other) ⇒ Object
72
73
74
|
# File 'lib/Namo/Formulae.rb', line 72
def merge(other)
self.class.new(@store.merge(other.to_h))
end
|
#reject(&block) ⇒ Object
76
77
78
|
# File 'lib/Namo/Formulae.rb', line 76
def reject(&block)
self.class.new(@store.reject(&block))
end
|
#required_parameter_count(name) ⇒ Object
46
47
48
49
|
# File 'lib/Namo/Formulae.rb', line 46
def required_parameter_count(name)
formula = self[name]
formula.arity >= 0 ? formula.arity : -formula.arity - 1
end
|
#to_h ⇒ Object
84
85
86
|
# File 'lib/Namo/Formulae.rb', line 84
def to_h
@store.dup
end
|