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
- #fraction_capacity ⇒ Object
- #fraction_capacity_count ⇒ Object
- #fraction_sub_capacity ⇒ Object
- #hundreds ⇒ Object
- #number_in_capacity(capacity) ⇒ Object
- #ones ⇒ Object
- #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 0 == count ? 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 |
#fraction_capacity ⇒ Object
54 55 56 |
# File 'lib/numbers_and_words/helper_classes/array_extensions/helpers.rb', line 54 def fraction_capacity [fraction_capacity_count, fraction_sub_capacity] end |
#fraction_capacity_count ⇒ Object
58 59 60 |
# File 'lib/numbers_and_words/helper_classes/array_extensions/helpers.rb', line 58 def fraction_capacity_count capacity_count.nil? ? sub_capacity : capacity_count + MICRO_CAPACITY_SHIFT end |
#fraction_sub_capacity ⇒ Object
62 63 64 |
# File 'lib/numbers_and_words/helper_classes/array_extensions/helpers.rb', line 62 def fraction_sub_capacity sub_capacity unless capacity_count.nil? end |
#hundreds ⇒ Object
42 43 44 |
# File 'lib/numbers_and_words/helper_classes/array_extensions/helpers.rb', line 42 def hundreds self[2].to_i if 0 < self[2].to_i 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 |
#ones ⇒ Object
26 27 28 |
# File 'lib/numbers_and_words/helper_classes/array_extensions/helpers.rb', line 26 def ones self[0].to_i if 0 < self[0].to_i end |
#ordinal_capacity ⇒ Object
70 71 72 73 |
# File 'lib/numbers_and_words/helper_classes/array_extensions/helpers.rb', line 70 def ordinal_capacity count = ordinal_index / FIGURES_IN_CAPACITY 0 == count ? nil : count end |
#ordinal_index ⇒ Object
66 67 68 |
# File 'lib/numbers_and_words/helper_classes/array_extensions/helpers.rb', line 66 def ordinal_index index { |figure| figure != 0 } end |
#round_hundred? ⇒ Boolean
46 47 48 |
# File 'lib/numbers_and_words/helper_classes/array_extensions/helpers.rb', line 46 def round_hundred? ones.nil? && tens.nil? end |
#sub_capacity ⇒ Object
50 51 52 |
# File 'lib/numbers_and_words/helper_classes/array_extensions/helpers.rb', line 50 def sub_capacity capacity_length % FIGURES_IN_CAPACITY end |
#teens ⇒ Object
30 31 32 |
# File 'lib/numbers_and_words/helper_classes/array_extensions/helpers.rb', line 30 def teens tens_with_ones if 1 == tens end |
#tens ⇒ Object
34 35 36 |
# File 'lib/numbers_and_words/helper_classes/array_extensions/helpers.rb', line 34 def tens self[1].to_i if self[1] && 0 < self[1].to_i end |
#tens_with_ones ⇒ Object
38 39 40 |
# File 'lib/numbers_and_words/helper_classes/array_extensions/helpers.rb', line 38 def tens_with_ones [ones, tens] if ones && tens end |