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


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_lengthObject


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_capacityObject


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

def fraction_capacity
  [fraction_capacity_count, fraction_sub_capacity]
end

#fraction_capacity_countObject


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

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

#fraction_sub_capacityObject


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

def fraction_sub_capacity
  sub_capacity unless capacity_count.nil?
end

#hundredsObject


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

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

#onesObject


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

#opaque?(capacity) ⇒ Boolean

Returns:

  • (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_capacityObject


85
86
87
88
# File 'lib/numbers_and_words/helper_classes/array_extensions/helpers.rb', line 85

def ordinal_capacity
  count = ordinal_index / FIGURES_IN_CAPACITY
  count.zero? ? nil : count
end

#ordinal_indexObject


81
82
83
# File 'lib/numbers_and_words/helper_classes/array_extensions/helpers.rb', line 81

def ordinal_index
  index(&:positive?)
end

#round_hundred?Boolean

Returns:

  • (Boolean)

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

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

#sub_capacityObject


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

def sub_capacity
  capacity_length % FIGURES_IN_CAPACITY
end

#teensObject


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

def teens
  tens_with_ones if tens == 1
end

#tensObject


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

def tens
  self[1].to_i if self[1].to_i.positive?
end

#tens_with_onesObject


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

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