class Faker::Measurement
Constants
- ALL
- NONE
Public Class Methods
height(amount = rand(10))
click to toggle source
# File lib/faker/measurement.rb, line 7 def height(amount = rand(10)) ensure_valid_amount(amount) if amount == ALL make_plural(fetch('measurement.height')) elsif amount == NONE fetch('measurement.height') else "#{amount.to_s} #{check_for_plural(fetch('measurement.height'), amount)}" end end
length(amount = rand(10))
click to toggle source
# File lib/faker/measurement.rb, line 18 def length(amount = rand(10)) ensure_valid_amount(amount) if amount == ALL make_plural(fetch('measurement.length')) elsif amount == NONE fetch('measurement.length') else "#{amount.to_s} #{check_for_plural(fetch('measurement.length'), amount)}" end end
metric_height(amount = rand(10))
click to toggle source
# File lib/faker/measurement.rb, line 51 def metric_height(amount = rand(10)) ensure_valid_amount(amount) if amount == ALL make_plural(fetch('measurement.height')) elsif amount == NONE fetch('measurement.height') else "#{amount.to_s} #{check_for_plural(fetch('measurement.height'), amount)}" end end
metric_length(amount = rand(10))
click to toggle source
# File lib/faker/measurement.rb, line 62 def metric_length(amount = rand(10)) ensure_valid_amount(amount) if amount == ALL make_plural(fetch('measurement.length')) elsif amount == NONE fetch('measurement.length') else "#{amount.to_s} #{check_for_plural(fetch('measurement.length'), amount)}" end end
metric_volume(amount = rand(10))
click to toggle source
# File lib/faker/measurement.rb, line 73 def metric_volume(amount = rand(10)) ensure_valid_amount(amount) if amount == ALL make_plural(fetch('measurement.volume')) elsif amount == NONE fetch('measurement.volume') else "#{amount.to_s} #{check_for_plural(fetch('measurement.volume'), amount)}" end end
metric_weight(amount = rand(10))
click to toggle source
# File lib/faker/measurement.rb, line 84 def metric_weight(amount = rand(10)) ensure_valid_amount(amount) if amount == ALL make_plural(fetch('measurement.weight')) elsif amount == NONE fetch('measurement.weight') else "#{amount.to_s} #{check_for_plural(fetch('measurement.weight'), amount)}" end end
volume(amount = rand(10))
click to toggle source
# File lib/faker/measurement.rb, line 29 def volume(amount = rand(10)) ensure_valid_amount(amount) if amount == ALL make_plural(fetch('measurement.volume')) elsif amount == NONE fetch('measurement.volume') else "#{amount.to_s} #{check_for_plural(fetch('measurement.volume'), amount)}" end end
weight(amount = rand(10))
click to toggle source
# File lib/faker/measurement.rb, line 40 def weight(amount = rand(10)) ensure_valid_amount(amount) if amount == ALL make_plural(fetch('measurement.weight')) elsif amount == NONE fetch('measurement.weight') else "#{amount.to_s} #{check_for_plural(fetch('measurement.weight'), amount)}" end end
Private Class Methods
check_for_plural(text, number)
click to toggle source
# File lib/faker/measurement.rb, line 103 def check_for_plural(text, number) if number && number != 1 make_plural(text) else text end end
ensure_valid_amount(amount)
click to toggle source
# File lib/faker/measurement.rb, line 97 def ensure_valid_amount(amount) unless amount == NONE || amount == ALL || amount.is_a?(Integer) || amount.is_a?(Float) raise ArgumentError, 'invalid amount' end end
make_plural(text)
click to toggle source
# File lib/faker/measurement.rb, line 111 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