Class: Pocketsphinx::Configuration::Base
- Inherits:
-
Object
- Object
- Pocketsphinx::Configuration::Base
- Defined in:
- lib/pocketsphinx/configuration/base.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#ps_config ⇒ Object
readonly
Returns the value of attribute ps_config.
-
#setting_definitions ⇒ Object
readonly
Returns the value of attribute setting_definitions.
Instance Method Summary collapse
-
#[](name) ⇒ Object
Get a configuration setting.
-
#[]=(name, value) ⇒ Object
Set a configuration setting with type checking.
-
#details(name = nil) ⇒ Object
Get details for one or all configuration settings.
-
#initialize ⇒ Base
constructor
A new instance of Base.
- #setting_names ⇒ Object
Constructor Details
#initialize ⇒ Base
Returns a new instance of Base.
7 8 9 10 11 12 13 |
# File 'lib/pocketsphinx/configuration/base.rb', line 7 def initialize @ps_arg_defs = API::Pocketsphinx.ps_args @setting_definitions = SettingDefinition.from_arg_defs(@ps_arg_defs) # Sets default settings based on definitions @ps_config = API::Sphinxbase.cmd_ln_parse_r(nil, @ps_arg_defs, 0, nil, 1) end |
Instance Attribute Details
#ps_config ⇒ Object (readonly)
Returns the value of attribute ps_config
4 5 6 |
# File 'lib/pocketsphinx/configuration/base.rb', line 4 def ps_config @ps_config end |
#setting_definitions ⇒ Object (readonly)
Returns the value of attribute setting_definitions
5 6 7 |
# File 'lib/pocketsphinx/configuration/base.rb', line 5 def setting_definitions @setting_definitions end |
Instance Method Details
#[](name) ⇒ Object
Get a configuration setting
40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/pocketsphinx/configuration/base.rb', line 40 def [](name) case find_definition(name).type when :integer API::Sphinxbase.cmd_ln_int_r(ps_config, "-#{name}") when :float API::Sphinxbase.cmd_ln_float_r(ps_config, "-#{name}") when :string API::Sphinxbase.cmd_ln_str_r(ps_config, "-#{name}") when :boolean API::Sphinxbase.cmd_ln_int_r(ps_config, "-#{name}") != 0 when :string_list raise NotImplementedError end end |
#[]=(name, value) ⇒ Object
Set a configuration setting with type checking
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/pocketsphinx/configuration/base.rb', line 56 def []=(name, value) check_type(name, type = find_definition(name).type, value) case type when :integer API::Sphinxbase.cmd_ln_set_int_r(ps_config, "-#{name}", value.to_i) when :float API::Sphinxbase.cmd_ln_set_float_r(ps_config, "-#{name}", value.to_f) when :string API::Sphinxbase.cmd_ln_set_str_r(ps_config, "-#{name}", (value.to_s if value)) when :boolean API::Sphinxbase.cmd_ln_set_int_r(ps_config, "-#{name}", value ? 1 : 0) when :string_list raise NotImplementedError end end |
#details(name = nil) ⇒ Object
Get details for one or all configuration settings
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/pocketsphinx/configuration/base.rb', line 22 def details(name = nil) details = [name || setting_names].flatten.map do |name| definition = find_definition(name) { name: name, type: definition.type, default: definition.default, required: definition.required?, value: self[name], info: definition.doc } end name ? details.first : details end |
#setting_names ⇒ Object
15 16 17 |
# File 'lib/pocketsphinx/configuration/base.rb', line 15 def setting_names setting_definitions.keys.sort end |