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



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

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

#delete(name) ⇒ Object



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

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

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



16
17
18
19
20
21
22
23
24
# File 'lib/Namo/Formulae.rb', line 16

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



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

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

#each(&block) ⇒ Object



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

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

#empty?Boolean

Returns:

  • (Boolean)


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

def empty?
  @store.empty?
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


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

def eql?(other)
  self == other
end

#hashObject



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

def hash
  keys.sort.hash
end

#key?(name) ⇒ Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/Namo/Formulae.rb', line 35

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

#keysObject



31
32
33
# File 'lib/Namo/Formulae.rb', line 31

def keys
  @store.keys
end

#merge(other) ⇒ Object



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

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

#reject(&block) ⇒ Object



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

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

#required_parameter_count(name) ⇒ Object



26
27
28
29
# File 'lib/Namo/Formulae.rb', line 26

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

#to_hObject



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

def to_h
  @store.dup
end