Class: FrequencyEnumerator
- Inherits:
-
Enumerable::Enumerator
- Object
- Enumerable::Enumerator
- FrequencyEnumerator
- Defined in:
- lib/frequency_enumerator/base.rb
Defined Under Namespace
Classes: Composer, Decomposer, Sorter
Instance Attribute Summary collapse
-
#bit_count ⇒ Object
readonly
Returns the value of attribute bit_count.
-
#frequencies ⇒ Object
readonly
Returns the value of attribute frequencies.
-
#from ⇒ Object
readonly
Returns the value of attribute from.
-
#to ⇒ Object
readonly
Returns the value of attribute to.
Instance Method Summary collapse
- #each(&block) ⇒ Object
-
#initialize(frequencies, params = {}) ⇒ FrequencyEnumerator
constructor
A new instance of FrequencyEnumerator.
- #limit ⇒ Object
Constructor Details
#initialize(frequencies, params = {}) ⇒ FrequencyEnumerator
Returns a new instance of FrequencyEnumerator.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/frequency_enumerator/base.rb', line 5 def initialize(frequencies, params = {}) @frequencies = frequencies @bit_count = params[:bit_count] || 6 @from = params[:from] || 0 @to = params[:to] || limit @offset = params[:offset] || 0 raise_if_either_boundary_is_out_of_range @sorter = params[:sorter] || fe::Sorter @composer = params[:composer] || fe::Composer @decomposer = params[:decomposer] || fe::Decomposer end |
Instance Attribute Details
#bit_count ⇒ Object (readonly)
Returns the value of attribute bit_count.
3 4 5 |
# File 'lib/frequency_enumerator/base.rb', line 3 def bit_count @bit_count end |
#frequencies ⇒ Object (readonly)
Returns the value of attribute frequencies.
3 4 5 |
# File 'lib/frequency_enumerator/base.rb', line 3 def frequencies @frequencies end |
#from ⇒ Object (readonly)
Returns the value of attribute from.
3 4 5 |
# File 'lib/frequency_enumerator/base.rb', line 3 def from @from end |
#to ⇒ Object (readonly)
Returns the value of attribute to.
3 4 5 |
# File 'lib/frequency_enumerator/base.rb', line 3 def to @to end |
Instance Method Details
#each(&block) ⇒ Object
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/frequency_enumerator/base.rb', line 20 def each(&block) (from..to).each do |i| binary = decomposer.decompose(i) bitmap = fragmented_bitmap(binary) result = composition(bitmap) yield offset(result) end self end |
#limit ⇒ Object
31 32 33 |
# File 'lib/frequency_enumerator/base.rb', line 31 def limit @limit ||= (2 ** bit_count) ** frequencies.size - 1 end |