Class: Topic

Inherits:
Object
  • Object
show all
Defined in:
lib/dbc_today/models/topic.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ Topic

Returns a new instance of Topic.



4
5
6
7
8
9
# File 'lib/dbc_today/models/topic.rb', line 4

def initialize(attributes)
  @phase = attributes.fetch(:phase)
  @week = attributes.fetch(:week)
  @day = attributes.fetch(:day)
  @description = attributes.fetch(:description)
end

Instance Attribute Details

#dayObject (readonly)

Returns the value of attribute day.



2
3
4
# File 'lib/dbc_today/models/topic.rb', line 2

def day
  @day
end

#descriptionObject (readonly)

Returns the value of attribute description.



2
3
4
# File 'lib/dbc_today/models/topic.rb', line 2

def description
  @description
end

#phaseObject (readonly)

Returns the value of attribute phase.



2
3
4
# File 'lib/dbc_today/models/topic.rb', line 2

def phase
  @phase
end

#weekObject (readonly)

Returns the value of attribute week.



2
3
4
# File 'lib/dbc_today/models/topic.rb', line 2

def week
  @week
end

Class Method Details

.allObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/dbc_today/models/topic.rb', line 11

def self.all
  list = []
  
  CSV.foreach(
    "#{current_directory}/../data/topics.csv",
    headers: true,
    header_converters: :symbol,
    skip_blanks: true
  ) do |row|
    list << Topic.new(row)
  end

  list
end

.current_directoryObject



34
35
36
# File 'lib/dbc_today/models/topic.rb', line 34

def self.current_directory
  File.expand_path File.dirname(__FILE__)
end

.where(args) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/dbc_today/models/topic.rb', line 26

def self.where(args)
  all.select { |topic|
    topic.phase == args[:phase] &&
      topic.week == args[:week] &&
      topic.day == args[:day]
  }
end