Class: Pocketsphinx::Configuration::SettingDefinition

Inherits:
Struct
  • Object
show all
Defined in:
lib/pocketsphinx/configuration/setting_definition.rb

Constant Summary collapse

TYPES =
[:integer, :float, :string, :boolean, :string_list]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#defltObject

Returns the value of attribute deflt

Returns:

  • (Object)

    the current value of deflt



3
4
5
# File 'lib/pocketsphinx/configuration/setting_definition.rb', line 3

def deflt
  @deflt
end

#docObject

Returns the value of attribute doc

Returns:

  • (Object)

    the current value of doc



3
4
5
# File 'lib/pocketsphinx/configuration/setting_definition.rb', line 3

def doc
  @doc
end

#nameObject

Returns the value of attribute name

Returns:

  • (Object)

    the current value of name



3
4
5
# File 'lib/pocketsphinx/configuration/setting_definition.rb', line 3

def name
  @name
end

#type_codeObject

Returns the value of attribute type_code

Returns:

  • (Object)

    the current value of 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

Parameters:

  • ps_arg_defs (FFI::Pointer)

    A pointer to the Pocketsphinx argument definitions

Returns:

  • (Hash)

    A hash of setting definitions (name -> definition)



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

#defaultObject

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

Returns:

  • (Boolean)


21
22
23
# File 'lib/pocketsphinx/configuration/setting_definition.rb', line 21

def required?
  type_code % 2 == 1
end

#typeObject



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