File: unit_metric.rb

package info (click to toggle)
ruby-ffaker 2.23.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,776 kB
  • sloc: ruby: 12,788; makefile: 8; sh: 1
file content (98 lines) | stat: -rw-r--r-- 1,867 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# frozen_string_literal: true

module FFaker
  module UnitMetric
    include FFaker::Unit

    extend ModuleUtils
    extend self

    LENGTH_UNITS = [
      { name: 'millimeters', abbreviation: 'mm' },
      { name: 'centimeters', abbreviation: 'cm' },
      { name: 'meters', abbreviation: 'm' },
      { name: 'kilometers', abbreviation: 'km' }
    ].freeze
    MASS_UNITS = [
      { name: 'gram', abbreviation: 'g' },
      { name: 'kilogram', abbreviation: 'kg' },
      { name: 'metric ton', abbreviation: 'mt' }
    ].freeze
    LIQUID_UNITS = [
      { name: 'milliliters', abbreviation: 'ml' },
      { name: 'liters', abbreviation: 'L' }
    ].freeze
    VOLUME_UNITS = [
      { name: ' cubic centimeters', abbreviation: 'cm^3' },
      { name: 'cubic meters', abbreviation: 'm^3' }
    ].freeze
    AREA_UNITS = [
      { name: 'centimeters squared', abbreviation: 'cm^2' },
      { name: 'meters squared', abbreviation: 'm^2' },
      { name: 'hectares', abbreviation: 'ha' },
      { name: 'kilometers', abbreviation: 'km' }
    ].freeze

    def mass_name
      mass[:name]
    end

    def mass_abbr
      mass[:abbreviation]
    end

    def length_name
      length[:name]
    end

    def length_abbr
      length[:abbreviation]
    end

    def liquid_name
      liquid[:name]
    end

    def liquid_abbr
      liquid[:abbreviation]
    end

    def volume_name
      volume[:name]
    end

    def volume_abbr
      volume[:abbreviation]
    end

    def area_name
      area[:name]
    end

    def area_abbr
      area[:abbreviation]
    end

    private

    def length
      fetch_sample(LENGTH_UNITS)
    end

    def mass
      fetch_sample(MASS_UNITS)
    end

    def liquid
      fetch_sample(LIQUID_UNITS)
    end

    def volume
      fetch_sample(VOLUME_UNITS)
    end

    def area
      fetch_sample(AREA_UNITS)
    end
  end
end