Module: HashPivot::Repository::Base

Included in:
ActiveRecordRepository, HashRepository, StructRepository
Defined in:
lib/hash_pivot/repository/base.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



6
7
8
# File 'lib/hash_pivot/repository/base.rb', line 6

def self.included(base)
  base.extend(ClassMethods)
end

Instance Method Details

#hash_by_groupHash

Returns:

  • (Hash)


30
31
32
33
34
35
36
# File 'lib/hash_pivot/repository/base.rb', line 30

def hash_by_group
  @data.group_by do |hash|
    @group.each_with_object({}) do |key, memo_obj|
      memo_obj[key] = hash[key]
    end
  end
end

#initialize(data, group, pivot_in) ⇒ Object

Parameters:

  • data (Array<Hash>)
  • group (Array)
  • pivot_in (Object)


23
24
25
26
27
# File 'lib/hash_pivot/repository/base.rb', line 23

def initialize(data, group, pivot_in)
  @data = translate_data(data)
  @group = group
  @pivot_in = pivot_in
end

#translate_data(_data) ⇒ Array<Hash>

Parameters:

  • _data (Array<Hash>)

Returns:

  • (Array<Hash>)

Raises:



40
41
42
# File 'lib/hash_pivot/repository/base.rb', line 40

def translate_data(_data)
  raise HashPivot::Error::NotImplementedError, 'translate_data is not implemented'
end