Class: Namo::Row

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

Instance Method Summary collapse

Instance Method Details

#==(other) ⇒ Object



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

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

#[](name) ⇒ Object



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

def [](name)
  if @formulae.key?(name)
    case @formulae[name].arity
    when 2
      raise_unless_namo_context(name)
      @formulae[name].call(self, @namo)
    else
      @formulae[name].call(self)
    end
  else
    @row[name]
  end
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#hashObject



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

def hash
  @row.hash
end

#match?(selections) ⇒ Boolean

Returns:

  • (Boolean)


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

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



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

def to_h
  @row
end