Class: Dict

Inherits:
Object
  • Object
show all
Defined in:
lib/mealib/dict.rb

Overview

Базовый класс для словарей из Dicts.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, index) ⇒ Dict

Returns a new instance of Dict.



6
7
8
9
# File 'lib/mealib/dict.rb', line 6

def initialize(id, index)
  @id    = id
  @index = index
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



4
5
6
# File 'lib/mealib/dict.rb', line 4

def id
  @id
end

#indexObject (readonly)

Returns the value of attribute index.



4
5
6
# File 'lib/mealib/dict.rb', line 4

def index
  @index
end

Class Method Details

.allObject



11
12
13
# File 'lib/mealib/dict.rb', line 11

def self.all
  constants.select { |const| (const_get const).class != Array }.map { |const| const_get const }                       # пока я не добавил константы типа ALL, работала эта строка: constants.map { |const| const_get const }
end

.find(id) ⇒ Object



15
16
17
# File 'lib/mealib/dict.rb', line 15

def self.find(id)
  all.select { |const| const.id == id.to_i }.first
end

.find_by_index(index) ⇒ Object



19
20
21
# File 'lib/mealib/dict.rb', line 19

def self.find_by_index(index)
  all.select { |const| const.index == index }.first
end

.where(ids) ⇒ Object



23
24
25
# File 'lib/mealib/dict.rb', line 23

def self.where(ids)
  all.select { |const| ids.include?(const.id) }
end