Class: Rubirai::Info Abstract
- Inherits:
-
Object
- Object
- Rubirai::Info
- Defined in:
- lib/rubirai/objects/info.rb
Overview
This class is abstract.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#bot ⇒ Object
readonly
Returns the value of attribute bot.
-
#raw ⇒ Object
readonly
Returns the value of attribute raw.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(hash, bot = nil) ⇒ Info
constructor
A new instance of Info.
- #to_h ⇒ Hash{String => Object}
Constructor Details
#initialize(hash, bot = nil) ⇒ Info
Returns a new instance of Info.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/rubirai/objects/info.rb', line 13 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 |
Instance Attribute Details
#bot ⇒ Object (readonly)
Returns the value of attribute bot.
39 40 41 |
# File 'lib/rubirai/objects/info.rb', line 39 def bot @bot end |
#raw ⇒ Object (readonly)
Returns the value of attribute raw.
39 40 41 |
# File 'lib/rubirai/objects/info.rb', line 39 def raw @raw end |
Class Method Details
.set_fields(*fields, **default_values) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/rubirai/objects/info.rb', line 13 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) ⇒ Object
34 35 36 37 |
# File 'lib/rubirai/objects/info.rb', line 34 def self.set_modifiable_fields(*fields) set_fields(*fields) attr_writer(*fields) end |
Instance Method Details
#to_h ⇒ Hash{String => Object}
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/rubirai/objects/info.rb', line 13 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 |