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, #shutdown

Constructor Details

#initialize(index:, position: :body, trigger: :oneshot, args: {}) ⇒ IndexRecord

Returns a new instance of IndexRecord.

Parameters:

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


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

def initialize(index:, position: :body, trigger: :oneshot, args: {})
  super()
  @index = index
  @position = position
  @trigger = trigger
  @args = args
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



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

def args
  @args
end

#indexObject

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

#triggerObject (readonly)

Returns the value of attribute trigger.



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

def trigger
  @trigger
end

Instance Method Details

#exist_on_conf?(index = @index) ⇒ Boolean

Parameters:

Returns:

  • (Boolean)


63
64
65
# File 'lib/fusuma/plugin/events/records/index_record.rb', line 63

def exist_on_conf?(index = @index)
  Config.search(index)
end

#merge(records:, index: @index) ⇒ IndexRecord, NilClass

FIXME: move to Config::Index

Parameters:

Returns:

  • (IndexRecord)

    when merge is succeeded

  • (NilClass)

    when merge is not succeeded



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/fusuma/plugin/events/records/index_record.rb', line 37

def merge(records:, index: @index)
  # FIXME: cache
  raise "position is NOT body: #{self}" unless mergeable?

  if records.empty?
    if Config.instance.find_execute_key(index)
      @index = index
      return self
    end
    return nil
  end

  record = records.shift
  new_index = case record.position
  when :surfix
    Config::Index.new([*index.keys, *record.index.keys])
  else
    raise "invalid index position: #{record}"
  end

  return unless exist_on_conf?(new_index)

  merge(records: records, index: new_index)
end

#mergeable?Boolean

Returns:

  • (Boolean)


79
80
81
# File 'lib/fusuma/plugin/events/records/index_record.rb', line 79

def mergeable?
  @position == :body
end

#to_sObject



25
26
27
# File 'lib/fusuma/plugin/events/records/index_record.rb', line 25

def to_s
  "#{@index}, #{@position}, #{@trigger}, #{@args}"
end

#trigger_priorityInteger

Returns:

  • (Integer)


68
69
70
71
72
73
74
75
76
77
# File 'lib/fusuma/plugin/events/records/index_record.rb', line 68

def trigger_priority
  case @trigger
  when :oneshot
    10
  when :repeat
    100
  else
    1000
  end
end

#typeObject



29
30
31
# File 'lib/fusuma/plugin/events/records/index_record.rb', line 29

def type
  :index
end