Class: Namo::Formulae

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/Namo/Formulae.rb

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



80
81
82
# File 'lib/Namo/Formulae.rb', line 80

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



60
61
62
# File 'lib/Namo/Formulae.rb', line 60

def delete(name)
  @store.delete(name)
end

#derive(name, row, namo, *arguments) ⇒ Object



28
29
30
31
32
33
34
35
36
# File 'lib/Namo/Formulae.rb', line 28

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

#dupObject



72
73
74
# File 'lib/Namo/Formulae.rb', line 72

def dup
  self.class.new(@store.dup)
end

#each(&block) ⇒ Object



55
56
57
58
# File 'lib/Namo/Formulae.rb', line 55

def each(&block)
  return enum_for(:each) unless block_given?
  @store.each(&block)
end

#empty?Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/Namo/Formulae.rb', line 51

def empty?
  @store.empty?
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


84
85
86
# File 'lib/Namo/Formulae.rb', line 84

def eql?(other)
  self == other
end

#hashObject



88
89
90
# File 'lib/Namo/Formulae.rb', line 88

def hash
  keys.sort.hash
end

#key?(name) ⇒ Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/Namo/Formulae.rb', line 47

def key?(name)
  @store.key?(name)
end

#keysObject



43
44
45
# File 'lib/Namo/Formulae.rb', line 43

def keys
  @store.keys
end

#merge(other) ⇒ Object



64
65
66
# File 'lib/Namo/Formulae.rb', line 64

def merge(other)
  self.class.new(@store.merge(other.to_h))
end

#reject(&block) ⇒ Object



68
69
70
# File 'lib/Namo/Formulae.rb', line 68

def reject(&block)
  self.class.new(@store.reject(&block))
end

#required_parameter_count(name) ⇒ Object



38
39
40
41
# File 'lib/Namo/Formulae.rb', line 38

def required_parameter_count(name)
  formula = self[name]
  formula.arity >= 0 ? formula.arity : -formula.arity - 1
end

#to_hObject



76
77
78
# File 'lib/Namo/Formulae.rb', line 76

def to_h
  @store.dup
end