class Rubirai::GroupInfo

The abstract class for group information @abstract

@!attribute [r] raw

@return [Hash{String => Object}] the raw hash

@!attribute [r] bot

@return [Bot] the bot

Attributes

bot[R]
raw[R]

Public Class Methods

new(hash, bot = nil) click to toggle source

@private

# File lib/rubirai/objects/group_info.rb, line 45
def initialize(hash, bot = nil)
  @raw = hash
  @bot = bot
end
set_fields(*fields, **default_values) click to toggle source

@private

Calls superclass method
# File lib/rubirai/objects/group_info.rb, line 15
def self.set_fields(*fields, **default_values)
  attr_reader(*fields)

  class_eval do
    define_method(:initialize) do |hash, bot = nil|
      # noinspection RubySuperCallWithoutSuperclassInspection
      super hash, bot
      fields.each do |field|
        value = hash[field.to_s.snake_to_camel(lower: true)] || default_values[field]
        instance_variable_set("@#{field}", value)
      end
    end

    define_method(:to_h) do
      fields.to_h do |field|
        [field.to_s.snake_to_camel(lower: true), instance_variable_get(field)]
      end.compact
    end
  end
end
set_modifiable_fields(*fields) click to toggle source

@private

# File lib/rubirai/objects/group_info.rb, line 37
def self.set_modifiable_fields(*fields)
  set_fields(*fields)
  attr_writer(*fields)
end