Class: FrequencyEnumerator::Decomposer
- Inherits:
-
Object
- Object
- FrequencyEnumerator::Decomposer
- Defined in:
- lib/frequency_enumerator/decomposer.rb
Instance Attribute Summary collapse
-
#bit_count ⇒ Object
readonly
Returns the value of attribute bit_count.
-
#endianness ⇒ Object
readonly
Returns the value of attribute endianness.
Class Method Summary collapse
Instance Method Summary collapse
- #big_endian? ⇒ Boolean
- #decompose(integer) ⇒ Object
-
#initialize(params = {}) ⇒ Decomposer
constructor
A new instance of Decomposer.
- #little_endian? ⇒ Boolean
Constructor Details
#initialize(params = {}) ⇒ Decomposer
Returns a new instance of Decomposer.
9 10 11 12 |
# File 'lib/frequency_enumerator/decomposer.rb', line 9 def initialize(params = {}) @bit_count = params[:bit_count] || 8 @endianness = params[:endianness] || :little end |
Instance Attribute Details
#bit_count ⇒ Object (readonly)
Returns the value of attribute bit_count.
6 7 8 |
# File 'lib/frequency_enumerator/decomposer.rb', line 6 def bit_count @bit_count end |
#endianness ⇒ Object (readonly)
Returns the value of attribute endianness.
7 8 9 |
# File 'lib/frequency_enumerator/decomposer.rb', line 7 def endianness @endianness end |
Class Method Details
.decompose(integer) ⇒ Object
14 15 16 |
# File 'lib/frequency_enumerator/decomposer.rb', line 14 def self.decompose(integer) new.decompose(integer) end |
Instance Method Details
#big_endian? ⇒ Boolean
31 32 33 |
# File 'lib/frequency_enumerator/decomposer.rb', line 31 def big_endian? endianess == :big end |
#decompose(integer) ⇒ Object
18 19 20 21 22 23 24 25 |
# File 'lib/frequency_enumerator/decomposer.rb', line 18 def decompose(integer) raise_if_negative(integer) raise_if_not_enough_bits(integer) bit_array = bit_count.times.map { |b| integer[b] } little_endian? ? bit_array : bit_array.reverse end |
#little_endian? ⇒ Boolean
27 28 29 |
# File 'lib/frequency_enumerator/decomposer.rb', line 27 def little_endian? endianness == :little end |