Sha256: 6f292962df4aa0fed35d5fc3cdcc28df542b0c21a678f36b9f24755ce2c8d9ab

Contents?: true

Size: 827 Bytes

Versions: 1

Compression:

Stored size: 827 Bytes

Contents

#! /usr/bin/env ruby
# coding: utf-8

require "yaml"

# Series name is composed only of alphabets.
# Host name is started by the series name and followed by integers.
# E.g.,
#   "Fe", "Fe00", "Fe01" are of series "Fe" and not "F"
#
class MachineInfo

  class NoEntryError < Exception; end

  #
  def initialize(data)
    @data = data
  end

  def self.load_file(data_file = (ENV["HOME"] + "/.machineinfo"))
    data = YAML.load_file(data_file)
    MachineInfo.new data
  end

  def get_info(host)
    series = host.sub(/\d*$/, "")
    unless @data.has_key?(series)
      raise NoEntryError,
        "#{series}"
    end
    @data[series]
  end

  #def has_info?(host)
  #  series = host.sub(/\d*$/, "")
  #  unless @data.has_key?(series)
  #    raise NoEntryError,
  #      "#{series}"
  #  end
  #  @data[series]
  #end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
comana-0.0.9 lib/comana/machineinfo.rb