module NumbersAndWords::ArrayExtensions::Helpers

Constants

FIGURES_IN_CAPACITY
MICRO_CAPACITY_SHIFT
ONES_SHIFT
THOUSAND_CAPACITY

Public Instance Methods

capacity_count() click to toggle source
# 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() click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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() click to toggle source
# 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() click to toggle source
# 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() click to toggle source
# 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() click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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() click to toggle source
# 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() click to toggle source
# File lib/numbers_and_words/helper_classes/array_extensions/helpers.rb, line 45
def only_ones
  ones if !tens && !hundreds
end
opaque?(capacity) click to toggle source
# 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() click to toggle source
# 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() click to toggle source
# File lib/numbers_and_words/helper_classes/array_extensions/helpers.rb, line 85
def ordinal_index
  index(&:positive?)
end
round_hundred?() click to toggle source
# File lib/numbers_and_words/helper_classes/array_extensions/helpers.rb, line 65
def round_hundred?
  ones.nil? && tens.nil?
end
sub_capacity() click to toggle source
# File lib/numbers_and_words/helper_classes/array_extensions/helpers.rb, line 69
def sub_capacity
  capacity_length % FIGURES_IN_CAPACITY
end
teens() click to toggle source
# File lib/numbers_and_words/helper_classes/array_extensions/helpers.rb, line 49
def teens
  tens_with_ones if tens == 1
end
tens() click to toggle source
# 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() click to toggle source
# File lib/numbers_and_words/helper_classes/array_extensions/helpers.rb, line 57
def tens_with_ones
  [ones, tens] if ones && tens
end