File: unit.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 (48 lines) | stat: -rw-r--r-- 951 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
# frozen_string_literal: true

module FFaker
  module Unit
    extend ModuleUtils
    extend self

    TIME_UNITS = [
      { name: 'Years', abbreviation: 'yr' },
      { name: 'Days', abbreviation: 'd' },
      { name: 'Hours', abbreviation: 'h' },
      { name: 'Minutes', abbreviation: 'm' },
      { name: 'Seconds', abbreviation: 's' },
      { name: 'Milliseconds', abbreviation: 'ms' }
    ].freeze
    TEMPERATURE_UNITS = [
      { name: 'Kelvin', abbreviation: 'K' },
      { name: 'Celsius', abbreviation: 'C' },
      { name: 'Fahrenheit', abbreviation: 'F' }
    ].freeze

    def time_name
      time[:name]
    end

    def time_abbr
      time[:abbreviation]
    end

    def temperature_name
      temperature[:name]
    end

    def temperature_abbr
      temperature[:abbreviation]
    end

    private

    def time
      fetch_sample(TIME_UNITS)
    end

    def temperature
      fetch_sample(TEMPERATURE_UNITS)
    end
  end
end