Module: Scale::Types::Enum

Defined Under Namespace

Modules: ClassMethods

Instance Attribute Summary collapse

Attributes included from Base

#value

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Base

#==, #initialize

Instance Attribute Details

#indexObject

Returns the value of attribute index.



253
254
255
# File 'lib/scale/base.rb', line 253

def index
  @index
end

Class Method Details

.included(base) ⇒ Object



296
297
298
# File 'lib/scale/base.rb', line 296

def self.included(base)
  base.extend(ClassMethods)
end

Instance Method Details

#encodeObject



300
301
302
303
304
305
306
# File 'lib/scale/base.rb', line 300

def encode
  if self.class.const_defined? "ITEMS"
    index.to_s(16).rjust(2, "0") + value.encode
  else
    self.class::VALUES.index(value).to_s(16).rjust(2, "0")
  end
end

#to_humanObject



308
309
310
311
312
313
314
315
316
# File 'lib/scale/base.rb', line 308

def to_human
  if self.class.const_defined? "ITEMS"
    @value.to_human
  elsif self.class.const_defined? "INNER_TYPES"
    @value.to_human
  else
    @value
  end
end