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

Instance Method Details

#capacity_countObject



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_lengthObject



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_capacityObject



62
63
64
# File 'lib/numbers_and_words/helper_classes/array_extensions/helpers.rb', line 62

def fraction_capacity
  [fraction_capacity_count, fraction_sub_capacity]
end

#fraction_capacity_countObject



66
67
68
# File 'lib/numbers_and_words/helper_classes/array_extensions/helpers.rb', line 66

def fraction_capacity_count
  capacity_count.nil? ? sub_capacity : capacity_count + MICRO_CAPACITY_SHIFT
end

#fraction_indexObject



58
59
60
# File 'lib/numbers_and_words/helper_classes/array_extensions/helpers.rb', line 58

def fraction_index
  index '.'
end

#fraction_sub_capacityObject



70
71
72
# File 'lib/numbers_and_words/helper_classes/array_extensions/helpers.rb', line 70

def fraction_sub_capacity
  sub_capacity unless capacity_count.nil?
end

#hundredsObject



46
47
48
# File 'lib/numbers_and_words/helper_classes/array_extensions/helpers.rb', line 46

def hundreds
  self[2].to_i if 0 < self[2].to_i
end

#is_a_thousand_capacity?(capacity) ⇒ Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/numbers_and_words/helper_classes/array_extensions/helpers.rb', line 26

def is_a_thousand_capacity? capacity
  THOUSAND_CAPACITY == capacity
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

#onesObject



30
31
32
# File 'lib/numbers_and_words/helper_classes/array_extensions/helpers.rb', line 30

def ones
  self[0].to_i if 0 < self[0].to_i
end

#ordinal_capacityObject



78
79
80
81
# File 'lib/numbers_and_words/helper_classes/array_extensions/helpers.rb', line 78

def ordinal_capacity
  count = ordinal_index / FIGURES_IN_CAPACITY
  0 == count ? nil : count
end

#ordinal_indexObject



74
75
76
# File 'lib/numbers_and_words/helper_classes/array_extensions/helpers.rb', line 74

def ordinal_index
  index { |figure| figure != 0 }
end

#round_hundred?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/numbers_and_words/helper_classes/array_extensions/helpers.rb', line 50

def round_hundred?
  ones.nil? && tens.nil?
end

#sub_capacityObject



54
55
56
# File 'lib/numbers_and_words/helper_classes/array_extensions/helpers.rb', line 54

def sub_capacity
  capacity_length % FIGURES_IN_CAPACITY
end

#teensObject



34
35
36
# File 'lib/numbers_and_words/helper_classes/array_extensions/helpers.rb', line 34

def teens
  tens_with_ones if 1 == tens
end

#tensObject



38
39
40
# File 'lib/numbers_and_words/helper_classes/array_extensions/helpers.rb', line 38

def tens
  self[1].to_i if self[1] && 0 < self[1].to_i
end

#tens_with_onesObject



42
43
44
# File 'lib/numbers_and_words/helper_classes/array_extensions/helpers.rb', line 42

def tens_with_ones
  [ones, tens] if ones && tens
end