Class: BCDice::Preprocessor

Inherits:
Object
  • Object
show all
Defined in:
lib/bcdice/preprocessor.rb

Overview

入力文字列に対して前処理を行う

Examples:

Preprocessor.process(
  "1d6+4D+(3*4) 切り取られる部分",
  game_system
) #=> "1d6+4D6+7"

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text, game_system) ⇒ Preprocessor

Returns a new instance of Preprocessor.

Parameters:

  • text (String)
  • game_system (Base)


20
21
22
23
# File 'lib/bcdice/preprocessor.rb', line 20

def initialize(text, game_system)
  @text = text
  @game_system = game_system
end

Class Method Details

.process(text, game_system) ⇒ String

Parameters:

  • text (String)
  • game_system (Base)

Returns:

  • (String)


14
15
16
# File 'lib/bcdice/preprocessor.rb', line 14

def self.process(text, game_system)
  Preprocessor.new(text, game_system).process()
end

Instance Method Details

#processString

Returns:

  • (String)


26
27
28
29
30
31
32
33
34
35
# File 'lib/bcdice/preprocessor.rb', line 26

def process
  trim_after_whitespace()
  replace_parentheses()

  @text = @game_system.change_text(@text)

  replace_implicit_d()

  return @text
end