Class: RatingChgkV2::Models::BaseModel
- Inherits:
-
Object
- Object
- RatingChgkV2::Models::BaseModel
- Defined in:
- lib/rating_chgk_v2/models/base_model.rb
Direct Known Subclasses
AuthenticationTokenModel, CountryModel, PlayerModel, PlayerSeasonModel, PlayerTournamentModel, RegionModel, ReleaseModel, SeasonModel, TeamModel, TeamTournamentModel, TournamentFlagModel, TournamentModel, TournamentResultModel, TournamentSynchAppealModel, TournamentSynchControversialModel, TournamentSynchRequestModel, TournamentTypeModel, TownModel, VenueModel, VenueTypeModel
Instance Attribute Summary collapse
-
#endpoint ⇒ Object
readonly
Returns the value of attribute endpoint.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(raw_data, endpoint = nil) ⇒ BaseModel
constructor
A new instance of BaseModel.
Constructor Details
#initialize(raw_data, endpoint = nil) ⇒ BaseModel
Returns a new instance of BaseModel.
14 15 16 17 18 19 20 |
# File 'lib/rating_chgk_v2/models/base_model.rb', line 14 def initialize(raw_data, endpoint = nil) @endpoint = endpoint self.class.const_get(:ATTRIBUTES).each do |att| instance_variable_set :"@#{att}", (raw_data[att] || raw_data[att.to_sym]) end end |
Instance Attribute Details
#endpoint ⇒ Object (readonly)
Returns the value of attribute endpoint.
8 9 10 |
# File 'lib/rating_chgk_v2/models/base_model.rb', line 8 def endpoint @endpoint end |
Class Method Details
.inherited(subclass) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/rating_chgk_v2/models/base_model.rb', line 22 def self.inherited(subclass) subclass.class_exec do filename = subclass.name.base_class_name.snakecase.delete_suffix('_model') attrs = YAML.load_file File.("../data/#{filename}.yml", __dir__) const_set :ATTRIBUTES, attrs attrs.each do |att| attr_reader(att) end end super end |
.load(method, endpoint) ⇒ Object
10 11 12 |
# File 'lib/rating_chgk_v2/models/base_model.rb', line 10 def self.load(method, endpoint) new endpoint.send(method), endpoint end |