Class: Tokogen::BitCombiner
- Inherits:
-
Object
- Object
- Tokogen::BitCombiner
- Defined in:
- lib/tokogen/bit_combiner.rb
Instance Attribute Summary collapse
-
#size ⇒ Object
readonly
Returns the value of attribute size.
Instance Method Summary collapse
-
#each(&block) ⇒ Object
rubocop:disable Metrics/MethodLength.
-
#initialize(bits_enum, width_in_bits) ⇒ BitCombiner
constructor
A new instance of BitCombiner.
Constructor Details
#initialize(bits_enum, width_in_bits) ⇒ BitCombiner
Returns a new instance of BitCombiner.
6 7 8 9 10 11 12 |
# File 'lib/tokogen/bit_combiner.rb', line 6 def initialize(bits_enum, width_in_bits) @bits_enum = bits_enum @width_in_bits = width_in_bits bits_enum_size = @bits_enum.size @size = bits_enum_size / @width_in_bits if bits_enum_size end |
Instance Attribute Details
#size ⇒ Object (readonly)
Returns the value of attribute size.
4 5 6 |
# File 'lib/tokogen/bit_combiner.rb', line 4 def size @size end |
Instance Method Details
#each(&block) ⇒ Object
rubocop:disable Metrics/MethodLength
14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/tokogen/bit_combiner.rb', line 14 def each(&block) # rubocop:disable Metrics/MethodLength enum = Enumerator.new(@size) do |y| @bits_enum.each_slice(@width_in_bits) do |slice| num = 0 slice.size.times do |i| num |= (slice[i] << i) end y.yield(num) end end return enum if block.nil? enum.each(&block) end |