module BioTCM

Top level namespace of BioTCM

Constants

DEFAULT_DATA_DIRECTORY

Default data directory

DEFAULT_META_FILE_URL

Default url of the meta file

VERSION

Current version

Public Instance Methods

curl(url, params: nil) click to toggle source

Get an url @param url [String] @return [String] the responce body @raise RuntimeError if return status is not 200

# File lib/biotcm.rb, line 24
def curl(url, params: nil)
  url += '?' + params.reject { |_, v| v.nil? }.map { |k, v| k.to_s + '=' + v.to_s }.join('&') if params

  res = Net::HTTP.get_response(URI(url))

  if res.is_a?(Net::HTTPOK)
    res.body
  else
    raise "HTTP status #{res.code} returned when trying to get #{url.inspect}"
  end
end
logger() click to toggle source

Get the logger @return [Logger]

# File lib/biotcm.rb, line 38
def logger
  @logger ||= Logger.new(STDOUT)
end
meta() click to toggle source

Get meta values @return [Hash]

# File lib/biotcm.rb, line 44
def meta
  @meta ||= YAML.load(curl(DEFAULT_META_FILE_URL))
rescue SocketError, RuntimeError
  @meta ||= YAML.load(File.read(File.expand_path('../../docs/meta.yaml', __FILE__)))
end
path_to(relative_path, mkdir_p: true) click to toggle source

Make a path for data @param relative_path [String] @return [String]

# File lib/biotcm.rb, line 53
def path_to(relative_path, mkdir_p: true)
  File.expand_path(relative_path, DEFAULT_DATA_DIRECTORY)
    .tap { |path| FileUtils.mkdir_p(File.dirname(path)) if mkdir_p }
end
stamp() click to toggle source

Get a stamp string containing time and thread_id @return [String] @example

BioTCM::Utility.stamp # => "20140314_011353_1bbfd18"
# File lib/biotcm.rb, line 62
def stamp
  Time.now.to_s.split(' ')[0..1]
    .push((Thread.current.object_id << 1).to_s(16))
    .join('_').gsub(/-|:/, '')
end