Sha256: 45facabc76516bf75663da31629a6636afe8e30b81cb4de455de56d1d044461a

Contents?: true

Size: 864 Bytes

Versions: 6

Compression:

Stored size: 864 Bytes

Contents

module Hue
  module Config
    class Bridge < Abstract

      def self.file_path
        File.join(ENV['HOME'], ".#{Hue.device_type}", 'bridges.yml')
      end

      def self.find(id)
        yaml = read_file(file_path)
        entry = yaml.select { |k,v| k.to_s == id.to_s }
        if entry.empty?
          nil
        else
          new(id, entry[id]['uri'])
        end
      end

      public

      attr_accessor :uri

      def initialize(id, uri, path = self.class.file_path)
        super(id, path)
        @uri = uri
      end

      def id
        self.name
      end

      def write(overwrite_existing_key = true)
        super(overwrite_existing_key)
      end

      private

      def add_self_to_yaml(yaml)
        key = id.dup.force_encoding('ASCII')
        yaml[key] = {'uri' => self.uri.force_encoding('ASCII')}
      end

    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
hue-lib-0.7.4 lib/hue/config/bridge.rb
hue-lib-0.7.3 lib/hue/config/bridge.rb
hue-lib-0.7.2 lib/hue/config/bridge.rb
hue-lib-0.7.1 lib/hue/config/bridge.rb
hue-lib-0.7.0 lib/hue/config/bridge.rb
hue-lib-0.6.0 lib/hue/config/bridge.rb