Sha256: 06c665f4e22bc1fef6172fd53c6ba9ad95f56d3602b25e481e5899f7a24e8b82

Contents?: true

Size: 650 Bytes

Versions: 3

Compression:

Stored size: 650 Bytes

Contents

require 'open-uri'

module Linodians
  ##
  # Employee object
  class Employee
    def initialize(params = {})
      @raw = params
    end

    def photo
      @photo ||= open(PHOTO_URL % username) { |x| x.read }
    end

    def [](value)
      @raw[value.to_sym] || @raw[value.to_s]
    end

    def to_json(*args, &block)
      @raw.to_json(*args, &block)
    end

    def respond_to?(method, _ = false)
      @raw.key?(method) || super
    end

    private

    def method_missing(method, *args, &block)
      return super unless @raw.key?(method)
      instance_eval "def #{method}() @raw[:'#{method}'] end"
      send(method)
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
linodians-0.0.4 lib/linodians/employee.rb
linodians-0.0.3 lib/linodians/employee.rb
linodians-0.0.2 lib/linodians/employee.rb