Class: Yosina::TransliteratorConfigListBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/yosina/recipes.rb

Overview

Internal builder for creating lists of transliterator configurations

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(head: [], tail: []) ⇒ TransliteratorConfigListBuilder

Returns a new instance of TransliteratorConfigListBuilder.



9
10
11
12
# File 'lib/yosina/recipes.rb', line 9

def initialize(head: [], tail: [])
  @head = head.dup
  @tail = tail.dup
end

Instance Attribute Details

#headObject (readonly)

Returns the value of attribute head.



7
8
9
# File 'lib/yosina/recipes.rb', line 7

def head
  @head
end

#tailObject (readonly)

Returns the value of attribute tail.



7
8
9
# File 'lib/yosina/recipes.rb', line 7

def tail
  @tail
end

Instance Method Details

#buildObject

Build the final configuration list



48
49
50
# File 'lib/yosina/recipes.rb', line 48

def build
  @head + @tail
end

#insert_head(config, force_replace: false) ⇒ Object

Insert config at the head of the chain



15
16
17
18
19
20
21
22
23
# File 'lib/yosina/recipes.rb', line 15

def insert_head(config, force_replace: false)
  idx = @head.find_index { |c| c[0] == config[0] }
  if idx
    @head[idx] = config if force_replace
  else
    @head.unshift(config)
  end
  self
end

#insert_middle(config, force_replace: false) ⇒ Object

Insert config in the middle (tail list, at beginning)



26
27
28
29
30
31
32
33
34
# File 'lib/yosina/recipes.rb', line 26

def insert_middle(config, force_replace: false)
  idx = @tail.find_index { |c| c[0] == config[0] }
  if idx
    @tail[idx] = config if force_replace
  else
    @tail.unshift(config)
  end
  self
end

#insert_tail(config, force_replace: false) ⇒ Object

Insert config at the tail of the chain



37
38
39
40
41
42
43
44
45
# File 'lib/yosina/recipes.rb', line 37

def insert_tail(config, force_replace: false)
  idx = @tail.find_index { |c| c[0] == config[0] }
  if idx
    @tail[idx] = config if force_replace
  else
    @tail.push(config)
  end
  self
end