class Faker::Measurement

Constants

ALL
NONE

Public Class Methods

height(legacy_amount = NOT_GIVEN, amount: rand(10)) click to toggle source
# File lib/faker/default/measurement.rb, line 9
def height(legacy_amount = NOT_GIVEN, amount: rand(10))
  warn_for_deprecated_arguments do |keywords|
    keywords << :amount if legacy_amount != NOT_GIVEN
  end

  define_measurement_locale(amount, 'height')
end
length(legacy_amount = NOT_GIVEN, amount: rand(10)) click to toggle source
# File lib/faker/default/measurement.rb, line 17
def length(legacy_amount = NOT_GIVEN, amount: rand(10))
  warn_for_deprecated_arguments do |keywords|
    keywords << :amount if legacy_amount != NOT_GIVEN
  end

  define_measurement_locale(amount, 'length')
end
metric_height(legacy_amount = NOT_GIVEN, amount: rand(10)) click to toggle source
# File lib/faker/default/measurement.rb, line 41
def metric_height(legacy_amount = NOT_GIVEN, amount: rand(10))
  warn_for_deprecated_arguments do |keywords|
    keywords << :amount if legacy_amount != NOT_GIVEN
  end

  define_measurement_locale(amount, 'metric_height')
end
metric_length(legacy_amount = NOT_GIVEN, amount: rand(10)) click to toggle source
# File lib/faker/default/measurement.rb, line 49
def metric_length(legacy_amount = NOT_GIVEN, amount: rand(10))
  warn_for_deprecated_arguments do |keywords|
    keywords << :amount if legacy_amount != NOT_GIVEN
  end

  define_measurement_locale(amount, 'metric_length')
end
metric_volume(legacy_amount = NOT_GIVEN, amount: rand(10)) click to toggle source
# File lib/faker/default/measurement.rb, line 57
def metric_volume(legacy_amount = NOT_GIVEN, amount: rand(10))
  warn_for_deprecated_arguments do |keywords|
    keywords << :amount if legacy_amount != NOT_GIVEN
  end

  define_measurement_locale(amount, 'metric_volume')
end
metric_weight(legacy_amount = NOT_GIVEN, amount: rand(10)) click to toggle source
# File lib/faker/default/measurement.rb, line 65
def metric_weight(legacy_amount = NOT_GIVEN, amount: rand(10))
  warn_for_deprecated_arguments do |keywords|
    keywords << :amount if legacy_amount != NOT_GIVEN
  end

  define_measurement_locale(amount, 'metric_weight')
end
volume(legacy_amount = NOT_GIVEN, amount: rand(10)) click to toggle source
# File lib/faker/default/measurement.rb, line 25
def volume(legacy_amount = NOT_GIVEN, amount: rand(10))
  warn_for_deprecated_arguments do |keywords|
    keywords << :amount if legacy_amount != NOT_GIVEN
  end

  define_measurement_locale(amount, 'volume')
end
weight(legacy_amount = NOT_GIVEN, amount: rand(10)) click to toggle source
# File lib/faker/default/measurement.rb, line 33
def weight(legacy_amount = NOT_GIVEN, amount: rand(10))
  warn_for_deprecated_arguments do |keywords|
    keywords << :amount if legacy_amount != NOT_GIVEN
  end

  define_measurement_locale(amount, 'weight')
end

Private Class Methods

check_for_plural(text, number) click to toggle source
# File lib/faker/default/measurement.rb, line 75
def check_for_plural(text, number)
  if number && number != 1
    make_plural(text)
  else
    text
  end
end
define_measurement_locale(amount, locale) click to toggle source
# File lib/faker/default/measurement.rb, line 83
def define_measurement_locale(amount, locale)
  ensure_valid_amount(amount)
  if amount == ALL
    make_plural(fetch("measurement.#{locale}"))
  elsif amount == NONE
    fetch("measurement.#{locale}")
  else
    locale = check_for_plural(fetch("measurement.#{locale}"), amount)

    "#{amount} #{locale}"
  end
end
ensure_valid_amount(amount) click to toggle source
# File lib/faker/default/measurement.rb, line 96
def ensure_valid_amount(amount)
  raise ArgumentError, 'invalid amount' unless amount == NONE || amount == ALL || amount.is_a?(Integer) || amount.is_a?(Float)
end
make_plural(text) click to toggle source
# File lib/faker/default/measurement.rb, line 100
def make_plural(text)
  case text
  when 'foot'
    'feet'
  when 'inch'
    'inches'
  when 'fluid ounce'
    'fluid ounces'
  when 'metric ton'
    'metric tons'
  else
    "#{text}s"
  end
end