Class: Yosina::TransliteratorConfigListBuilder
- Inherits:
-
Object
- Object
- Yosina::TransliteratorConfigListBuilder
- Defined in:
- lib/yosina/recipes.rb
Overview
Internal builder for creating lists of transliterator configurations
Instance Attribute Summary collapse
-
#head ⇒ Object
readonly
Returns the value of attribute head.
-
#tail ⇒ Object
readonly
Returns the value of attribute tail.
Instance Method Summary collapse
-
#build ⇒ Object
Build the final configuration list.
-
#initialize(head: [], tail: []) ⇒ TransliteratorConfigListBuilder
constructor
A new instance of TransliteratorConfigListBuilder.
-
#insert_head(config, force_replace: false) ⇒ Object
Insert config at the head of the chain.
-
#insert_middle(config, force_replace: false) ⇒ Object
Insert config in the middle (tail list, at beginning).
-
#insert_tail(config, force_replace: false) ⇒ Object
Insert config at the tail of the chain.
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
#head ⇒ Object (readonly)
Returns the value of attribute head.
7 8 9 |
# File 'lib/yosina/recipes.rb', line 7 def head @head end |
#tail ⇒ Object (readonly)
Returns the value of attribute tail.
7 8 9 |
# File 'lib/yosina/recipes.rb', line 7 def tail @tail end |
Instance Method Details
#build ⇒ Object
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 |