Class: Cane::CLI::Translator
- Inherits:
-
Struct
- Object
- Struct
- Cane::CLI::Translator
- Defined in:
- lib/cane/cli/translator.rb
Overview
Translates CLI options with given defaults to a hash suitable to be passed to ‘Cane.run`.
Instance Attribute Summary collapse
-
#defaults ⇒ Object
Returns the value of attribute defaults.
-
#options ⇒ Object
Returns the value of attribute options.
Instance Method Summary collapse
- #check_disabled(check, params) ⇒ Object
- #option_with_default(key) ⇒ Object
- #to_hash ⇒ Object
- #translate_abc_options(result) ⇒ Object
- #translate_doc_options(result) ⇒ Object
- #translate_style_options(result) ⇒ Object
Instance Attribute Details
#defaults ⇒ Object
Returns the value of attribute defaults
6 7 8 |
# File 'lib/cane/cli/translator.rb', line 6 def defaults @defaults end |
#options ⇒ Object
Returns the value of attribute options
6 7 8 |
# File 'lib/cane/cli/translator.rb', line 6 def @options end |
Instance Method Details
#check_disabled(check, params) ⇒ Object
39 40 41 42 43 |
# File 'lib/cane/cli/translator.rb', line 39 def check_disabled(check, params) = .keys & params + [check] check == [-1] end |
#option_with_default(key) ⇒ Object
45 46 47 |
# File 'lib/cane/cli/translator.rb', line 45 def option_with_default(key) .fetch(key, defaults.fetch(key)) end |
#to_hash ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/cane/cli/translator.rb', line 7 def to_hash result = {} (result) (result) (result) result[:threshold] = .fetch(:threshold, []) result[:max_violations] = option_with_default(:max_violations).to_i result end |
#translate_abc_options(result) ⇒ Object
19 20 21 22 23 24 |
# File 'lib/cane/cli/translator.rb', line 19 def (result) result[:abc] = { files: option_with_default(:abc_glob), max: option_with_default(:abc_max).to_i } unless check_disabled(:no_abc, [:abc_glob, :abc_max]) end |
#translate_doc_options(result) ⇒ Object
33 34 35 36 37 |
# File 'lib/cane/cli/translator.rb', line 33 def (result) result[:doc] = { files: option_with_default(:doc_glob), } unless check_disabled(:no_doc, [:doc_glob]) end |
#translate_style_options(result) ⇒ Object
26 27 28 29 30 31 |
# File 'lib/cane/cli/translator.rb', line 26 def (result) result[:style] = { files: option_with_default(:style_glob), measure: option_with_default(:style_measure).to_i, } unless check_disabled(:no_style, [:style_glob]) end |