Sha256: b982c92a630d0f1e6e8b453a9055d2fb34529fee82bb918f01fb3ffa77839804

Contents?: true

Size: 762 Bytes

Versions: 1

Compression:

Stored size: 762 Bytes

Contents

require 'mayu/relation'

module Mayu
  Ap = Struct.new(:key, :name, :description, :map_key, :map_x, :map_y, keyword_init: true) do
    include Mayu::Relation

    def self.load(obj)
      new(**obj)
    end

    relates :map

    relates :associations

    def devices
      @devices ||= associations.map(&:device).compact
    end
    def users
      @users ||= devices.uniq(&:user_key).map(&:user).compact
    end

    def associations_count
      associations.size
    end
    def devices_count
      devices.size
    end
    def users_count
      users.size
    end

    def as_json
      {
        key: key,
        name: name,
        description: description,
        map_key: map_key,
        map_x: map_x,
        map_y: map_y,
      }
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mayu-0.1.0.beta1 lib/mayu/ap.rb