Module: NumbersAndWords::ArrayExtensions::Helpers
- Included in:
- FiguresArray
- Defined in:
- lib/numbers_and_words/helper_classes/array_extensions/helpers.rb
Constant Summary collapse
- MICRO_CAPACITY_SHIFT =
2
- FIGURES_IN_CAPACITY =
3
- THOUSAND_CAPACITY =
1
- ONES_SHIFT =
1
Instance Method Summary collapse
- #capacity_count ⇒ Object
- #capacity_length ⇒ Object
- #figures_array_in_capacity(capacity) ⇒ Object
- #figures_array_under_capacity(capacity) ⇒ Object
- #fraction_capacity ⇒ Object
- #fraction_capacity_count ⇒ Object
- #fraction_sub_capacity ⇒ Object
- #hundreds ⇒ Object
- #number_in_capacity(capacity) ⇒ Object
- #number_under_capacity(capacity) ⇒ Object
- #ones ⇒ Object
- #only_ones ⇒ Object
- #opaque?(capacity) ⇒ Boolean
- #ordinal_capacity ⇒ Object
- #ordinal_index ⇒ Object
- #round_hundred? ⇒ Boolean
- #sub_capacity ⇒ Object
- #teens ⇒ Object
- #tens ⇒ Object
- #tens_with_ones ⇒ Object
Instance Method Details
#capacity_count ⇒ Object
15 16 17 18 |
# File 'lib/numbers_and_words/helper_classes/array_extensions/helpers.rb', line 15 def capacity_count count = capacity_length / FIGURES_IN_CAPACITY count.zero? ? nil : count end |
#capacity_length ⇒ Object
11 12 13 |
# File 'lib/numbers_and_words/helper_classes/array_extensions/helpers.rb', line 11 def capacity_length length - ONES_SHIFT end |
#figures_array_in_capacity(capacity) ⇒ Object
20 21 22 |
# File 'lib/numbers_and_words/helper_classes/array_extensions/helpers.rb', line 20 def figures_array_in_capacity(capacity) self[capacity * FIGURES_IN_CAPACITY, FIGURES_IN_CAPACITY] end |
#figures_array_under_capacity(capacity) ⇒ Object
37 38 39 |
# File 'lib/numbers_and_words/helper_classes/array_extensions/helpers.rb', line 37 def figures_array_under_capacity(capacity) self[0..(capacity * FIGURES_IN_CAPACITY) - ONES_SHIFT] end |
#fraction_capacity ⇒ Object
73 74 75 |
# File 'lib/numbers_and_words/helper_classes/array_extensions/helpers.rb', line 73 def fraction_capacity [fraction_capacity_count, fraction_sub_capacity] end |
#fraction_capacity_count ⇒ Object
77 78 79 |
# File 'lib/numbers_and_words/helper_classes/array_extensions/helpers.rb', line 77 def fraction_capacity_count capacity_count.nil? ? sub_capacity : capacity_count + MICRO_CAPACITY_SHIFT end |
#fraction_sub_capacity ⇒ Object
81 82 83 |
# File 'lib/numbers_and_words/helper_classes/array_extensions/helpers.rb', line 81 def fraction_sub_capacity sub_capacity unless capacity_count.nil? end |
#hundreds ⇒ Object
61 62 63 |
# File 'lib/numbers_and_words/helper_classes/array_extensions/helpers.rb', line 61 def hundreds self[2].to_i if self[2].to_i.positive? end |
#number_in_capacity(capacity) ⇒ Object
24 25 26 |
# File 'lib/numbers_and_words/helper_classes/array_extensions/helpers.rb', line 24 def number_in_capacity(capacity) figures_array_in_capacity(capacity).reverse.join.to_i end |
#number_under_capacity(capacity) ⇒ Object
28 29 30 |
# File 'lib/numbers_and_words/helper_classes/array_extensions/helpers.rb', line 28 def number_under_capacity(capacity) figures_array_under_capacity(capacity).reverse.join.to_i end |
#ones ⇒ Object
41 42 43 |
# File 'lib/numbers_and_words/helper_classes/array_extensions/helpers.rb', line 41 def ones self[0].to_i if self[0].to_i.positive? end |
#only_ones ⇒ Object
45 46 47 |
# File 'lib/numbers_and_words/helper_classes/array_extensions/helpers.rb', line 45 def only_ones ones if !tens && !hundreds end |
#opaque?(capacity) ⇒ Boolean
32 33 34 35 |
# File 'lib/numbers_and_words/helper_classes/array_extensions/helpers.rb', line 32 def opaque?(capacity) figures_under = figures_array_under_capacity(capacity) figures_under.count(0) == figures_under.length end |
#ordinal_capacity ⇒ Object
89 90 91 92 |
# File 'lib/numbers_and_words/helper_classes/array_extensions/helpers.rb', line 89 def ordinal_capacity count = ordinal_index / FIGURES_IN_CAPACITY count.zero? ? nil : count end |
#ordinal_index ⇒ Object
85 86 87 |
# File 'lib/numbers_and_words/helper_classes/array_extensions/helpers.rb', line 85 def ordinal_index index(&:positive?) end |
#round_hundred? ⇒ Boolean
65 66 67 |
# File 'lib/numbers_and_words/helper_classes/array_extensions/helpers.rb', line 65 def round_hundred? ones.nil? && tens.nil? end |
#sub_capacity ⇒ Object
69 70 71 |
# File 'lib/numbers_and_words/helper_classes/array_extensions/helpers.rb', line 69 def sub_capacity capacity_length % FIGURES_IN_CAPACITY end |
#teens ⇒ Object
49 50 51 |
# File 'lib/numbers_and_words/helper_classes/array_extensions/helpers.rb', line 49 def teens tens_with_ones if tens == 1 end |
#tens ⇒ Object
53 54 55 |
# File 'lib/numbers_and_words/helper_classes/array_extensions/helpers.rb', line 53 def tens self[1].to_i if self[1].to_i.positive? end |
#tens_with_ones ⇒ Object
57 58 59 |
# File 'lib/numbers_and_words/helper_classes/array_extensions/helpers.rb', line 57 def tens_with_ones [ones, tens] if ones && tens end |