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
- #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
13 14 15 16 |
# File 'lib/numbers_and_words/helper_classes/array_extensions/helpers.rb', line 13 def capacity_count count = capacity_length / FIGURES_IN_CAPACITY count.zero? ? nil : count end |
#capacity_length ⇒ Object
9 10 11 |
# File 'lib/numbers_and_words/helper_classes/array_extensions/helpers.rb', line 9 def capacity_length length - ONES_SHIFT end |
#figures_array_in_capacity(capacity) ⇒ Object
18 19 20 |
# File 'lib/numbers_and_words/helper_classes/array_extensions/helpers.rb', line 18 def figures_array_in_capacity(capacity) self[capacity * FIGURES_IN_CAPACITY, FIGURES_IN_CAPACITY] end |
#figures_array_under_capacity(capacity) ⇒ Object
35 36 37 |
# File 'lib/numbers_and_words/helper_classes/array_extensions/helpers.rb', line 35 def figures_array_under_capacity(capacity) self[0..(capacity * FIGURES_IN_CAPACITY) - ONES_SHIFT] end |
#fraction_capacity ⇒ Object
67 68 69 |
# File 'lib/numbers_and_words/helper_classes/array_extensions/helpers.rb', line 67 def fraction_capacity [fraction_capacity_count, fraction_sub_capacity] end |
#fraction_capacity_count ⇒ Object
71 72 73 |
# File 'lib/numbers_and_words/helper_classes/array_extensions/helpers.rb', line 71 def fraction_capacity_count capacity_count.nil? ? sub_capacity : capacity_count + MICRO_CAPACITY_SHIFT end |
#fraction_sub_capacity ⇒ Object
75 76 77 |
# File 'lib/numbers_and_words/helper_classes/array_extensions/helpers.rb', line 75 def fraction_sub_capacity sub_capacity unless capacity_count.nil? end |
#hundreds ⇒ Object
55 56 57 |
# File 'lib/numbers_and_words/helper_classes/array_extensions/helpers.rb', line 55 def hundreds self[2].to_i if self[2].to_i > 0 end |
#number_in_capacity(capacity) ⇒ Object
22 23 24 |
# File 'lib/numbers_and_words/helper_classes/array_extensions/helpers.rb', line 22 def number_in_capacity(capacity) figures_array_in_capacity(capacity).reverse.join.to_i end |
#number_under_capacity(capacity) ⇒ Object
26 27 28 |
# File 'lib/numbers_and_words/helper_classes/array_extensions/helpers.rb', line 26 def number_under_capacity(capacity) figures_array_under_capacity(capacity).reverse.join.to_i end |
#ones ⇒ Object
39 40 41 |
# File 'lib/numbers_and_words/helper_classes/array_extensions/helpers.rb', line 39 def ones self[0].to_i if self[0].to_i > 0 end |
#opaque?(capacity) ⇒ Boolean
30 31 32 33 |
# File 'lib/numbers_and_words/helper_classes/array_extensions/helpers.rb', line 30 def opaque?(capacity) figures_under = figures_array_under_capacity(capacity) figures_under.count(0) == figures_under.length end |
#ordinal_capacity ⇒ Object
83 84 85 86 |
# File 'lib/numbers_and_words/helper_classes/array_extensions/helpers.rb', line 83 def ordinal_capacity count = ordinal_index / FIGURES_IN_CAPACITY count.zero? ? nil : count end |
#ordinal_index ⇒ Object
79 80 81 |
# File 'lib/numbers_and_words/helper_classes/array_extensions/helpers.rb', line 79 def ordinal_index index { |figure| figure != 0 } end |
#round_hundred? ⇒ Boolean
59 60 61 |
# File 'lib/numbers_and_words/helper_classes/array_extensions/helpers.rb', line 59 def round_hundred? ones.nil? && tens.nil? end |
#sub_capacity ⇒ Object
63 64 65 |
# File 'lib/numbers_and_words/helper_classes/array_extensions/helpers.rb', line 63 def sub_capacity capacity_length % FIGURES_IN_CAPACITY end |
#teens ⇒ Object
43 44 45 |
# File 'lib/numbers_and_words/helper_classes/array_extensions/helpers.rb', line 43 def teens tens_with_ones if tens == 1 end |
#tens ⇒ Object
47 48 49 |
# File 'lib/numbers_and_words/helper_classes/array_extensions/helpers.rb', line 47 def tens self[1].to_i if self[1] && self[1].to_i > 0 end |
#tens_with_ones ⇒ Object
51 52 53 |
# File 'lib/numbers_and_words/helper_classes/array_extensions/helpers.rb', line 51 def tens_with_ones [ones, tens] if ones && tens end |