Class: SlowBlink::Message::BINARY Abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/slow_blink/message/binary.rb

Overview

This class is abstract.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value) ⇒ BINARY

Note:

calls #set(value)

Returns a new instance of BINARY.



71
72
73
# File 'lib/slow_blink/message/binary.rb', line 71

def initialize(value)
    set(value)                
end

Class Method Details

.sizeInteger?

Returns maximum size of string in bytes.

Returns:

  • (Integer, nil)

    maximum size of string in bytes



45
46
47
# File 'lib/slow_blink/message/binary.rb', line 45

def self.size
    @type.size
end

.typeObject



27
28
29
# File 'lib/slow_blink/message/binary.rb', line 27

def self.type
    @type
end

Instance Method Details

#getString

Returns:

  • (String)


50
51
52
# File 'lib/slow_blink/message/binary.rb', line 50

def get
    @value
end

#set(value) ⇒ Object

Set a binary value

Parameters:

  • value (String)

Raises:

  • (TypeError)
  • (RangeError)

    value is larger than size



58
59
60
61
62
63
64
65
66
67
68
# File 'lib/slow_blink/message/binary.rb', line 58

def set(value)
    if value.kind_of? String
        if !self.class.size or value.size <= self.class.size
            @value = value.to_s
        else
            raise RangeError.new "String instance cannot be larger than #{self.class.size} bytes"
        end
    else
        raise TypeError.new "expecting a String instance"
    end
end

#to_tagObject



80
81
82
# File 'lib/slow_blink/message/binary.rb', line 80

def to_tag
    @value.bytes.map{ |c| sprintf("\\x%02X",c) }.join
end