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
95
96
97
|
# File 'lib/Namo/Formulae.rb', line 95
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
21
22
23
24
25
|
# File 'lib/Namo/Formulae.rb', line 16
def attach(modul)
unless modul.include?(Namo::Formulary)
raise ArgumentError, "not a Namo::Formulary: #{modul}"
end
host.extend(modul)
modul.public_instance_methods(false).each do |name|
@store[name] = host.method(name)
end
self
end
|
#delete(name) ⇒ Object
75
76
77
|
# File 'lib/Namo/Formulae.rb', line 75
def delete(name)
@store.delete(name)
end
|
#derive(name, row, namo, *arguments) ⇒ Object
43
44
45
46
47
48
49
50
51
|
# File 'lib/Namo/Formulae.rb', line 43
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/Namo/Formulae.rb', line 28
def detach(constituent)
case constituent
when Symbol
@store.delete(constituent)
when Module
unless constituent.include?(Namo::Formulary)
raise ArgumentError, "not a Namo::Formulary: #{constituent}"
end
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
87
88
89
|
# File 'lib/Namo/Formulae.rb', line 87
def dup
self.class.new(@store.dup)
end
|
#each(&block) ⇒ Object
70
71
72
73
|
# File 'lib/Namo/Formulae.rb', line 70
def each(&block)
return enum_for(:each) unless block_given?
@store.each(&block)
end
|
#empty? ⇒ Boolean
66
67
68
|
# File 'lib/Namo/Formulae.rb', line 66
def empty?
@store.empty?
end
|
#eql?(other) ⇒ Boolean
99
100
101
|
# File 'lib/Namo/Formulae.rb', line 99
def eql?(other)
self == other
end
|
#hash ⇒ Object
103
104
105
|
# File 'lib/Namo/Formulae.rb', line 103
def hash
keys.sort.hash
end
|
#key?(name) ⇒ Boolean
62
63
64
|
# File 'lib/Namo/Formulae.rb', line 62
def key?(name)
@store.key?(name)
end
|
#keys ⇒ Object
58
59
60
|
# File 'lib/Namo/Formulae.rb', line 58
def keys
@store.keys
end
|
#merge(other) ⇒ Object
79
80
81
|
# File 'lib/Namo/Formulae.rb', line 79
def merge(other)
self.class.new(@store.merge(other.to_h))
end
|
#reject(&block) ⇒ Object
83
84
85
|
# File 'lib/Namo/Formulae.rb', line 83
def reject(&block)
self.class.new(@store.reject(&block))
end
|
#required_parameter_count(name) ⇒ Object
53
54
55
56
|
# File 'lib/Namo/Formulae.rb', line 53
def required_parameter_count(name)
formula = self[name]
formula.arity >= 0 ? formula.arity : -formula.arity - 1
end
|
#to_h ⇒ Object
91
92
93
|
# File 'lib/Namo/Formulae.rb', line 91
def to_h
@store.dup
end
|