Module: Scale::Types::FixedWidthInt
Defined Under Namespace
Modules: ClassMethods
Instance Attribute Summary
Attributes included from Base
#value
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Base
#==, #initialize, #to_human
Class Method Details
.included(base) ⇒ Object
111
112
113
|
# File 'lib/scale/base.rb', line 111
def self.included(base)
base.extend(ClassMethods)
end
|
Instance Method Details
#encode ⇒ Object
115
116
117
118
119
120
121
122
|
# File 'lib/scale/base.rb', line 115
def encode
if value.class != ::Integer
raise "#{self.class}'s value must be integer"
end
bit_length = self.class::BYTE_LENGTH * 8
hex = value.to_unsigned(bit_length).to_s(16).hex_to_bytes.reverse.bytes_to_hex
hex[2..]
end
|