Class: Ligo::Accessory
- Inherits:
-
Object
- Object
- Ligo::Accessory
- Includes:
- Logging
- Defined in:
- lib/ligo/accessory.rb
Overview
A virtual accessory to interact via usb with an android device according to the Android Open Accessory Protocol.
Constant Summary collapse
- DEFAULT_ID =
The default id used to initialize a new accessory if none is provided to the constructor
{ manufacturer: 'ligō', model: 'Demo', description: 'ligō virtual accessory', version: '1.0', uri: 'https://github.com/nibua-r/ligo#readme', # 'ligō 1.0'.each_byte {|c| print c.to_i.to_s(16), '' } serial: '6c6967c58d20312e30' }
Instance Attribute Summary collapse
-
#description ⇒ String
readonly
Returns the
description
identifying string. -
#id ⇒ Hash<Symbol, String>
readonly
Returns the full identifying information hash.
-
#manufacturer ⇒ String
readonly
Returns the
manufacturer name
identifying string. -
#model ⇒ String
readonly
Returns the
model name
identifying string. -
#serial ⇒ String
readonly
Returns the
serial
identifying string. -
#uri ⇒ String
readonly
Returns the
uri
identifying string. -
#version ⇒ String
readonly
Returns the
version
identifying string.
Instance Method Summary collapse
-
#each(&block) ⇒ Object
Returns #id.each.
-
#initialize(id = DEFAULT_ID) ⇒ Accessory
constructor
Returns a new Accessory initialized with the provided identification.
-
#keys ⇒ Array
Returns #id.keys.
Methods included from Logging
configure_logger_for, configure_logger_output, #logger, logger_for
Constructor Details
#initialize(id = DEFAULT_ID) ⇒ Accessory
Returns a new Ligo::Accessory initialized with the provided identification
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/ligo/accessory.rb', line 123 def initialize(id = DEFAULT_ID) unless id.is_a? Hash raise ArgumentError, '#new must be called with a Hash' end required_ids = [:manufacturer, :model, :description, :version, :uri, :serial] required_ids.each do |sym| raise ArgumentError, "Missing argument: #{sym}" unless id.include? sym end id.each do |k, v| raise ArgumentError, "#{k} is not a String" unless v.is_a? String raise ArgumentError, "#{k} must not be empty" if v.empty? if v.bytesize > 255 raise ArgumentError, "#{k} must contain at most 255 bytes" end instance_variable_set "@#{k}", v unless v.nil? end @id = id logger.debug self.inspect end |
Instance Attribute Details
#description ⇒ String (readonly)
Returns the description
identifying string
80 81 82 |
# File 'lib/ligo/accessory.rb', line 80 def description @description end |
#id ⇒ Hash<Symbol, String> (readonly)
Returns the full identifying information hash
56 57 58 |
# File 'lib/ligo/accessory.rb', line 56 def id @id end |
#manufacturer ⇒ String (readonly)
Returns the manufacturer name
identifying string
64 65 66 |
# File 'lib/ligo/accessory.rb', line 64 def manufacturer @manufacturer end |
#model ⇒ String (readonly)
Returns the model name
identifying string
72 73 74 |
# File 'lib/ligo/accessory.rb', line 72 def model @model end |
#serial ⇒ String (readonly)
Returns the serial
identifying string
104 105 106 |
# File 'lib/ligo/accessory.rb', line 104 def serial @serial end |
#uri ⇒ String (readonly)
Returns the uri
identifying string
96 97 98 |
# File 'lib/ligo/accessory.rb', line 96 def uri @uri end |
#version ⇒ String (readonly)
Returns the version
identifying string
88 89 90 |
# File 'lib/ligo/accessory.rb', line 88 def version @version end |