Class: Lunar::NumberMatches

Inherits:
Object
  • Object
show all
Defined in:
lib/lunar/number_matches.rb

Overview

given ‘nest`, `att` and it’s ‘val`.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(nest, att, value) ⇒ NumberMatches

Returns a new instance of NumberMatches.



9
10
11
12
13
# File 'lib/lunar/number_matches.rb', line 9

def initialize(nest, att, value)
  @nest   = nest
  @att    = att
  @values = value.kind_of?(Enumerable) ? value : [value]
end

Instance Attribute Details

#attObject (readonly)

Returns the value of attribute att.



6
7
8
# File 'lib/lunar/number_matches.rb', line 6

def att
  @att
end

#nestObject (readonly)

Returns the value of attribute nest.



5
6
7
# File 'lib/lunar/number_matches.rb', line 5

def nest
  @nest
end

#valuesObject (readonly)

Returns the value of attribute values.



7
8
9
# File 'lib/lunar/number_matches.rb', line 7

def values
  @values
end

Instance Method Details

#distkeyObject



15
16
17
18
19
20
21
22
23
24
# File 'lib/lunar/number_matches.rb', line 15

def distkey
  case keys.size
  when 0 then nil
  when 1 then keys.first
  else
    nest[{ att => values }.hash].tap do |dk|
      dk.zunionstore keys.flatten
    end
  end
end