Class: Fusuma::Plugin::Events::Records::IndexRecord

Inherits:
Record
  • Object
show all
Defined in:
lib/fusuma/plugin/events/records/index_record.rb

Overview

Vector Record have index

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#config_index, #config_param_types, #config_params, inherited, plugins

Constructor Details

#initialize(index:, position: :body) ⇒ IndexRecord

Returns a new instance of IndexRecord.

Parameters:

  • index (Config::Index)
  • position (Symbol) (defaults to: :body)
    :prefix, :body, :surfix


16
17
18
19
# File 'lib/fusuma/plugin/events/records/index_record.rb', line 16

def initialize(index:, position: :body)
  @index = index
  @position = position
end

Instance Attribute Details

#indexObject (readonly)

define gesture format



11
12
13
# File 'lib/fusuma/plugin/events/records/index_record.rb', line 11

def index
  @index
end

#positionObject (readonly)

Returns the value of attribute position.



12
13
14
# File 'lib/fusuma/plugin/events/records/index_record.rb', line 12

def position
  @position
end

Instance Method Details

#mergable?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/fusuma/plugin/events/records/index_record.rb', line 43

def mergable?
  @position == :body
end

#merge(records:) ⇒ IndexRecord

Parameters:

Returns:



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/fusuma/plugin/events/records/index_record.rb', line 27

def merge(records:)
  raise "position is NOT body: #{self}" unless mergable?

  @index = records.reduce(@index) do |merged_index, record|
    case record.position
    when :prefix
      Config::Index.new([*record.index.keys, *merged_index.keys])
    when :surfix
      Config::Index.new([*merged_index.keys, *record.index.keys])
    else
      raise "invalid index position: #{record}"
    end
  end
  self
end

#typeObject



21
22
23
# File 'lib/fusuma/plugin/events/records/index_record.rb', line 21

def type
  :index
end