Class: Pocketsphinx::Configuration::SettingDefinition
- Inherits:
-
Struct
- Object
- Struct
- Pocketsphinx::Configuration::SettingDefinition
- Defined in:
- lib/pocketsphinx/configuration/setting_definition.rb
Constant Summary collapse
- TYPES =
[:integer, :float, :string, :boolean, :string_list]
Instance Attribute Summary collapse
-
#deflt ⇒ Object
Returns the value of attribute deflt.
-
#doc ⇒ Object
Returns the value of attribute doc.
-
#name ⇒ Object
Returns the value of attribute name.
-
#type_code ⇒ Object
Returns the value of attribute type_code.
Class Method Summary collapse
-
.from_arg_defs(ps_arg_defs) ⇒ Hash
Build setting definitions from pocketsphinx argument definitions.
Instance Method Summary collapse
-
#default ⇒ Object
Convert string defaults from pocketsphinx to Ruby types.
- #required? ⇒ Boolean
- #type ⇒ Object
Instance Attribute Details
#deflt ⇒ Object
Returns the value of attribute deflt
3 4 5 |
# File 'lib/pocketsphinx/configuration/setting_definition.rb', line 3 def deflt @deflt end |
#doc ⇒ Object
Returns the value of attribute doc
3 4 5 |
# File 'lib/pocketsphinx/configuration/setting_definition.rb', line 3 def doc @doc end |
#name ⇒ Object
Returns the value of attribute name
3 4 5 |
# File 'lib/pocketsphinx/configuration/setting_definition.rb', line 3 def name @name end |
#type_code ⇒ Object
Returns the value of attribute type_code
3 4 5 |
# File 'lib/pocketsphinx/configuration/setting_definition.rb', line 3 def type_code @type_code end |
Class Method Details
.from_arg_defs(ps_arg_defs) ⇒ Hash
Build setting definitions from pocketsphinx argument definitions
30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/pocketsphinx/configuration/setting_definition.rb', line 30 def self.from_arg_defs(ps_arg_defs) {}.tap do |setting_defs| arg_array = FFI::Pointer.new(API::Sphinxbase::Argument, ps_arg_defs) 0.upto(Float::INFINITY) do |i| arg = API::Sphinxbase::Argument.new(arg_array[i]) break if arg[:name].nil? # Remove '-' from argument name name = arg[:name][1..-1] setting_defs[name] = new(name, arg[:type], arg[:deflt], arg[:doc]) end end end |
Instance Method Details
#default ⇒ Object
Convert string defaults from pocketsphinx to Ruby types
12 13 14 15 16 17 18 19 |
# File 'lib/pocketsphinx/configuration/setting_definition.rb', line 12 def default case type when :integer then deflt.to_i when :float then deflt.to_f when :boolean then deflt == 'yes' else deflt end end |
#required? ⇒ Boolean
21 22 23 |
# File 'lib/pocketsphinx/configuration/setting_definition.rb', line 21 def required? type_code % 2 == 1 end |
#type ⇒ Object
6 7 8 9 |
# File 'lib/pocketsphinx/configuration/setting_definition.rb', line 6 def type # Remove the required bit if it exists and find type from log2 of code TYPES[Math.log2(type_code - type_code%2) - 1] end |