Class: Rubirai::GroupInfo Abstract
- Inherits:
-
Object
- Object
- Rubirai::GroupInfo
- Defined in:
- lib/rubirai/objects/group_info.rb
Overview
This class is abstract.
The abstract class for group information
Direct Known Subclasses
Instance Attribute Summary collapse
-
#bot ⇒ Bot
readonly
The bot.
-
#raw ⇒ Hash{String => Object}
readonly
The raw hash.
Instance Attribute Details
#bot ⇒ Bot (readonly)
Returns the bot.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/rubirai/objects/group_info.rb', line 13 class GroupInfo # @private 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 # @private def self.set_modifiable_fields(*fields) set_fields(*fields) attr_writer(*fields) end attr_reader :raw, :bot # @private def initialize(hash, bot = nil) @raw = hash @bot = bot end end |
#raw ⇒ Hash{String => Object} (readonly)
Returns the raw hash.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/rubirai/objects/group_info.rb', line 13 class GroupInfo # @private 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 # @private def self.set_modifiable_fields(*fields) set_fields(*fields) attr_writer(*fields) end attr_reader :raw, :bot # @private def initialize(hash, bot = nil) @raw = hash @bot = bot end end |