Class: Namo::Row

Inherits:
Object
  • Object
show all
Defined in:
lib/Namo/Row.rb

Instance Method Summary collapse

Instance Method Details

#==(other) ⇒ Object



21
22
23
# File 'lib/Namo/Row.rb', line 21

def ==(other)
  other.is_a?(Row) && @row == other.to_h
end

#[](name, *arguments) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/Namo/Row.rb', line 6

def [](name, *arguments)
  raise_unless_expected_arguments(name, arguments)
  if @formulae.key?(name)
    formula = @formulae[name]
    if collection_scoped?(formula)
      raise_unless_namo_context(name)
      formula.call(self, @namo, *arguments)
    else
      formula.call(self)
    end
  else
    @row[name]
  end
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/Namo/Row.rb', line 25

def eql?(other)
  other.is_a?(Row) && @row.eql?(other.to_h)
end

#hashObject



29
30
31
# File 'lib/Namo/Row.rb', line 29

def hash
  @row.hash
end

#match?(selections) ⇒ Boolean

Returns:

  • (Boolean)


33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/Namo/Row.rb', line 33

def match?(selections)
  selections.all? do |dimension, coordinate|
    case coordinate
    when Array, Range
      coordinate.include?(self[dimension])
    when Proc
      coordinate.call(self[dimension])
    when Regexp
      coordinate.match?(self[dimension].to_s)
    else
      self[dimension] == coordinate
    end
  end
end

#to_hObject



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

def to_h
  @row
end