Module: TreasureData::Helpers

Included in:
Command
Defined in:
lib/td/helpers.rb

Class Method Summary collapse

Class Method Details

.format_with_delimiter(number, delimiter = ',') ⇒ Object



5
6
7
# File 'lib/td/helpers.rb', line 5

def format_with_delimiter(number, delimiter = ',')
  number.to_s.gsub(/(\d)(?=(?:\d{3})+(?!\d))/, "\\1#{delimiter}")
end

.home_directoryObject



9
10
11
# File 'lib/td/helpers.rb', line 9

def home_directory
  on_windows? ? ENV['USERPROFILE'].gsub("\\","/") : ENV['HOME']
end

.on_64bit_os?Boolean

Returns:

  • (Boolean)


21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/td/helpers.rb', line 21

def on_64bit_os?
  if on_windows?
    if ENV.fetch('PROCESSOR_ARCHITECTURE', '').downcase.include? 'amd64'
      return true
    end
    return ENV.has_key?('PROCESSOR_ARCHITEW6432')
  else
    require 'open3'
    out, status = Open3.capture2('uname', '-m')
    raise 'Failed to detect OS bitness' unless status.success?
    return out.downcase.include? 'x86_64'
  end
end

.on_mac?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/td/helpers.rb', line 17

def on_mac?
  RUBY_PLATFORM =~ /-darwin\d/
end

.on_windows?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/td/helpers.rb', line 13

def on_windows?
  RUBY_PLATFORM =~ /mswin32|mingw32|mingw-ucrt/
end