Class: FrequencyEnumerator::Composer
- Inherits:
-
Object
- Object
- FrequencyEnumerator::Composer
- Defined in:
- lib/frequency_enumerator/composer.rb
Instance Attribute Summary collapse
-
#endianess ⇒ Object
readonly
Returns the value of attribute endianess.
Class Method Summary collapse
Instance Method Summary collapse
- #big_endian? ⇒ Boolean
- #compose(bit_array) ⇒ Object
-
#initialize(params = {}) ⇒ Composer
constructor
A new instance of Composer.
- #little_endian? ⇒ Boolean
Constructor Details
#initialize(params = {}) ⇒ Composer
Returns a new instance of Composer.
5 6 7 |
# File 'lib/frequency_enumerator/composer.rb', line 5 def initialize(params = {}) @endianess = params[:endianess] end |
Instance Attribute Details
#endianess ⇒ Object (readonly)
Returns the value of attribute endianess.
3 4 5 |
# File 'lib/frequency_enumerator/composer.rb', line 3 def endianess @endianess end |
Class Method Details
.compose(bit_array) ⇒ Object
9 10 11 |
# File 'lib/frequency_enumerator/composer.rb', line 9 def self.compose(bit_array) new.compose(bit_array) end |
Instance Method Details
#big_endian? ⇒ Boolean
27 28 29 |
# File 'lib/frequency_enumerator/composer.rb', line 27 def big_endian? @endianess == :big end |
#compose(bit_array) ⇒ Object
13 14 15 16 17 18 19 20 21 |
# File 'lib/frequency_enumerator/composer.rb', line 13 def compose(bit_array) raise_if_non_binary_elements(bit_array) bit_array = bit_array.reverse if big_endian? bit_array.each_with_index.inject(0) do |sum, (bit, index)| sum + (bit << index) end end |
#little_endian? ⇒ Boolean
23 24 25 |
# File 'lib/frequency_enumerator/composer.rb', line 23 def little_endian? @endianess == :little end |