Class: Sangi::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/sangi/config.rb

Constant Summary collapse

VALID_MODES =
%i[edu hist].freeze
VALID_ZERO_MODES =
%i[blank digit circle].freeze
VALID_SIGN_MODES =
%i[modern slash color dual].freeze
VALID_EXPLAIN_MODES =
%i[none brief learn].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(mode: :edu, zero_mode: nil, sign_mode: nil, explain_mode: :brief, all: false, export_path: nil, max_digits: 8, max_steps: 10_000, color: true) ⇒ Config

Returns a new instance of Config.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/sangi/config.rb', line 11

def initialize(
  mode: :edu,
  zero_mode: nil,
  sign_mode: nil,
  explain_mode: :brief,
  all: false,
  export_path: nil,
  max_digits: 8,
  max_steps: 10_000,
  color: true
)
  @mode = normalize_symbol(mode)
  @zero_mode = normalize_symbol(zero_mode) || default_zero_mode(@mode)
  @sign_mode = normalize_symbol(sign_mode) || default_sign_mode(@mode)
  @explain_mode = normalize_symbol(explain_mode)
  @all = all
  @export_path = export_path
  @max_digits = Integer(max_digits)
  @max_steps = Integer(max_steps)
  @color = color ? true : false
  validate!
rescue ArgumentError
  raise ValidationError, "数値オプションには整数を指定してください。"
end

Instance Attribute Details

#allObject (readonly)

Returns the value of attribute all.



9
10
11
# File 'lib/sangi/config.rb', line 9

def all
  @all
end

#colorObject (readonly)

Returns the value of attribute color.



9
10
11
# File 'lib/sangi/config.rb', line 9

def color
  @color
end

#explain_modeObject (readonly)

Returns the value of attribute explain_mode.



8
9
10
# File 'lib/sangi/config.rb', line 8

def explain_mode
  @explain_mode
end

#export_pathObject (readonly)

Returns the value of attribute export_path.



9
10
11
# File 'lib/sangi/config.rb', line 9

def export_path
  @export_path
end

#max_digitsObject (readonly)

Returns the value of attribute max_digits.



9
10
11
# File 'lib/sangi/config.rb', line 9

def max_digits
  @max_digits
end

#max_stepsObject (readonly)

Returns the value of attribute max_steps.



9
10
11
# File 'lib/sangi/config.rb', line 9

def max_steps
  @max_steps
end

#modeObject (readonly)

Returns the value of attribute mode.



8
9
10
# File 'lib/sangi/config.rb', line 8

def mode
  @mode
end

#sign_modeObject (readonly)

Returns the value of attribute sign_mode.



8
9
10
# File 'lib/sangi/config.rb', line 8

def sign_mode
  @sign_mode
end

#zero_modeObject (readonly)

Returns the value of attribute zero_mode.



8
9
10
# File 'lib/sangi/config.rb', line 8

def zero_mode
  @zero_mode
end

Instance Method Details

#with(**overrides) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/sangi/config.rb', line 36

def with(**overrides)
  Config.new(
    mode: overrides.fetch(:mode, mode),
    zero_mode: overrides.fetch(:zero_mode, zero_mode),
    sign_mode: overrides.fetch(:sign_mode, sign_mode),
    explain_mode: overrides.fetch(:explain_mode, explain_mode),
    all: overrides.fetch(:all, all),
    export_path: overrides.fetch(:export_path, export_path),
    max_digits: overrides.fetch(:max_digits, max_digits),
    max_steps: overrides.fetch(:max_steps, max_steps),
    color: overrides.fetch(:color, color)
  )
end