Class: ActiveHll::Hll

Inherits:
Object
  • Object
show all
Defined in:
lib/active_hll/hll.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value) ⇒ Hll

Returns a new instance of Hll.



7
8
9
10
11
12
13
# File 'lib/active_hll/hll.rb', line 7

def initialize(value)
  unless value.is_a?(String) && value.encoding == Encoding::BINARY
    raise ArgumentError, "Expected binary string"
  end

  @value = value
end

Instance Attribute Details

#valueObject (readonly)

Returns the value of attribute value.



5
6
7
# File 'lib/active_hll/hll.rb', line 5

def value
  @value
end

Instance Method Details

#dataObject



44
45
46
47
48
49
# File 'lib/active_hll/hll.rb', line 44

def data
  case type
  when 2
    value[3..-1].unpack("q>*")
  end
end

#expthreshObject



39
40
41
42
# File 'lib/active_hll/hll.rb', line 39

def expthresh
  t = value[2].unpack1("C") & 0b00111111
  t == 63 ? -1 : 2**(t - 1)
end

#inspectObject



15
16
17
# File 'lib/active_hll/hll.rb', line 15

def inspect
  "(hll)"
end

#log2mObject



31
32
33
# File 'lib/active_hll/hll.rb', line 31

def log2m
  value[1].unpack1("C") & 0b00011111
end

#regwidthObject



27
28
29
# File 'lib/active_hll/hll.rb', line 27

def regwidth
  (value[1].unpack1("C") >> 5) + 1
end

#schema_versionObject



19
20
21
# File 'lib/active_hll/hll.rb', line 19

def schema_version
  value[0].unpack1("C") >> 4
end

#sparseonObject



35
36
37
# File 'lib/active_hll/hll.rb', line 35

def sparseon
  (value[2].unpack1("C") & 0b01000000) >> 6
end

#typeObject



23
24
25
# File 'lib/active_hll/hll.rb', line 23

def type
  value[0].unpack1("C") & 0b00001111
end