Sha256: eb2a49a9d7bbefe07c19a0302a1b121ecbab184adcbf28f00eee43a8c7054151

Contents?: true

Size: 1.05 KB

Versions: 3

Compression:

Stored size: 1.05 KB

Contents

module Reality
  module Describers
    module Abstract
      class Base
        extend Memoist

        def get(id)
          # we assume that child was good and returned observations about only one entity, basically
          observations_for(id).yield_self(&method(:make_entities)).first
        end

        def query(params)
          Query.new(prefix, params)
        end

        memoize def log
          Logger.new(STDOUT).tap { |l| l.level = Logger::INFO }
        end

        private

        # To redefine in children
        def descriptor
          fail NotImplementedError
        end

        def observations_for(id)
          fail NotImplementedError
        end

        # Internal helpers

        def make_entities(observations)
          observations.group_by(&:entity_uri).map { |_, group|
            Entity.new(group)
          }
        end

        def obs(entity_id, name, value, source: nil, time: nil)
          Observation.new([prefix, entity_id].join('://'), name, value, time: time, source: source)
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
reality-0.1.0.alpha3 lib/reality/describers/abstract/base.rb
reality-0.1.0.alpha2 lib/reality/describers/abstract/base.rb
reality-0.1.0.alpha lib/reality/describers/abstract/base.rb