Class: BLE::CharDesc
- Inherits:
-
Object
- Object
- BLE::CharDesc
- Defined in:
- lib/ble/char_desc.rb
Instance Attribute Summary collapse
-
#desc ⇒ Object
readonly
Returns the value of attribute desc.
Instance Method Summary collapse
- #config ⇒ Object
- #flag?(flag_name) ⇒ Boolean
- #flags ⇒ Object
-
#initialize(desc) ⇒ CharDesc
constructor
A new instance of CharDesc.
- #post_process(val) ⇒ Object
- #pre_process(val) ⇒ Object
- #read_post_processor? ⇒ Boolean
-
#read_processors? ⇒ Boolean
Does incoming values have processors configured? If yes, the value needs to be post-processed after being received.
- #uuid ⇒ Object
-
#verifier? ⇒ Boolean
It has been configured a verifier preprocessor to check outgoing data?.
-
#verifies?(val) ⇒ Boolean
Is the received value verified by the verifier?.
- #write_pre_processor? ⇒ Boolean
-
#write_processors? ⇒ Boolean
Does outgoing values have processors configured? If yes, the value needs to be pre-processed before being send.
Constructor Details
#initialize(desc) ⇒ CharDesc
Returns a new instance of CharDesc.
8 9 10 |
# File 'lib/ble/char_desc.rb', line 8 def initialize(desc) @desc= desc end |
Instance Attribute Details
#desc ⇒ Object (readonly)
Returns the value of attribute desc
6 7 8 |
# File 'lib/ble/char_desc.rb', line 6 def desc @desc end |
Instance Method Details
#config ⇒ Object
14 15 16 |
# File 'lib/ble/char_desc.rb', line 14 def config @config||= Characteristic[@desc[:uuid]] end |
#flag?(flag_name) ⇒ Boolean
21 22 23 |
# File 'lib/ble/char_desc.rb', line 21 def flag?(flag_name) flags.include?(flag_name) end |
#flags ⇒ Object
11 12 13 |
# File 'lib/ble/char_desc.rb', line 11 def flags @flags||= @desc[:flags] end |
#post_process(val) ⇒ Object
58 59 60 |
# File 'lib/ble/char_desc.rb', line 58 def post_process(val) val = config[:in].call(val) if read_post_processor? end |
#pre_process(val) ⇒ Object
50 51 52 53 54 55 56 |
# File 'lib/ble/char_desc.rb', line 50 def pre_process(val) if verifier? && !verifies?(val) raise ArgumentError, "bad value for characteristic '#{uuid}'" end val = config[:out].call(val) if write_pre_processor? end |
#read_post_processor? ⇒ Boolean
43 44 45 |
# File 'lib/ble/char_desc.rb', line 43 def read_post_processor? config[:in] end |
#read_processors? ⇒ Boolean
Does incoming values have processors configured? If yes, the value needs to be post-processed after being received.
32 33 34 |
# File 'lib/ble/char_desc.rb', line 32 def read_processors? config && read_post_processor? end |
#uuid ⇒ Object
18 19 20 |
# File 'lib/ble/char_desc.rb', line 18 def uuid @desc[:uuid] end |
#verifier? ⇒ Boolean
It has been configured a verifier preprocessor to check outgoing data?
37 38 39 |
# File 'lib/ble/char_desc.rb', line 37 def verifier? config[:vrfy] end |
#verifies?(val) ⇒ Boolean
Is the received value verified by the verifier?
47 48 49 |
# File 'lib/ble/char_desc.rb', line 47 def verifies?(val) config[:vrfy].call(val) end |
#write_pre_processor? ⇒ Boolean
40 41 42 |
# File 'lib/ble/char_desc.rb', line 40 def write_pre_processor? config[:out] end |
#write_processors? ⇒ Boolean
Does outgoing values have processors configured? If yes, the value needs to be pre-processed before being send.
27 28 29 |
# File 'lib/ble/char_desc.rb', line 27 def write_processors? verifier? or write_pre_processor? end |