Class: HIDAPI::Language

Inherits:
Object
  • Object
show all
Defined in:
lib/hidapi/language.rb

Overview

List of all known USB languages.

Class Method Summary collapse

Class Method Details

.[](name) ⇒ Object

Gets a language by key or name.


146
147
148
# File 'lib/hidapi/language.rb', line 146

def self.[](name)
  get_by_name(name)
end

.[]=(*args) ⇒ Object

:nodoc:


151
152
153
# File 'lib/hidapi/language.rb', line 151

def self.[]=(*args)
  raise 'can\'t modify constants'
end

.get(language) ⇒ Object

Gets a language.

The input value can be the name, code, or USB code.


190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
# File 'lib/hidapi/language.rb', line 190

def self.get(language)
  if language.is_a?(Numeric)
    get_by_usb_code(language)
  elsif language.is_a?(Symbol) || language.is_a?(String)
    get_by_name(language) || get_by_code(language)
  elsif language.is_a?(Hash)
    if language[:usb_code]
      get_by_usb_code(language[:usb_code])
    elsif language[:code]
      get_by_code(language[:code])
    elsif language[:name]
      get_by_name(language[:name])
    else
      nil
    end
  else
    nil
  end
end

.get_by_code(code) ⇒ Object

Gets a language by code.


172
173
174
175
176
# File 'lib/hidapi/language.rb', line 172

def self.get_by_code(code)
  code = code.to_s.downcase
  res = KNOWN.find{|k,v| v[:code] == code}
  return res[1] if res && res.length == 2
end

.get_by_name(name) ⇒ Object

Gets a language by name.


158
159
160
161
162
163
164
165
166
167
168
# File 'lib/hidapi/language.rb', line 158

def self.get_by_name(name)
  name_sym = name.to_s.upcase.to_sym
  name = name.to_s.downcase
  if KNOWN.keys.include?(name_sym)
    return KNOWN[name_sym]
  else
    res = KNOWN.find{|k,v| v[:name].downcase == name}
    return res[1] if res && res.length == 2
  end
  nil
end

.get_by_usb_code(code) ⇒ Object

Gets a language by USB code.


180
181
182
183
184
# File 'lib/hidapi/language.rb', line 180

def self.get_by_usb_code(code)
  code = code.to_i
  res = KNOWN.find{|k,v| v[:usb_code] == code}
  return res[1] if res && res.length == 2
end

.method_missing(m, *a, &b) ⇒ Object

:nodoc:


211
212
213
214
215
216
217
# File 'lib/hidapi/language.rb', line 211

def self.method_missing(m,*a,&b)
  if KNOWN.respond_to?(m)
    KNOWN.send m, *a, &b
  else
    super m, *a, &b
  end
end