Class: Status

Inherits:
Object
  • Object
show all
Defined in:
app/models/status.rb

Constant Summary collapse

@@statuses =
[
  Status.new(id: 1,   name: 'Draft'),
  Status.new(id: 50,  name: 'Reviewed'),
  Status.new(id: 90,  name: 'Scheduled'),
  Status.new(id: 100, name: 'Published'),
  Status.new(id: 101, name: 'Hidden'),
]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Status

Returns a new instance of Status.



4
5
6
7
8
# File 'app/models/status.rb', line 4

def initialize(options = {})
  options = options.symbolize_keys
  @id = options[:id]
  @name = options[:name]
end

Instance Attribute Details

#idObject

Returns the value of attribute id.



2
3
4
# File 'app/models/status.rb', line 2

def id
  @id
end

#nameObject

Returns the value of attribute name.



2
3
4
# File 'app/models/status.rb', line 2

def name
  @name
end

Class Method Details

.[](value) ⇒ Object



14
15
16
# File 'app/models/status.rb', line 14

def self.[](value)
  @@statuses.find { |status| status.symbol == value.to_s.downcase.intern }
end

.find(id) ⇒ Object



18
19
20
# File 'app/models/status.rb', line 18

def self.find(id)
  @@statuses.find { |status| status.id.to_s == id.to_s }
end

.find_allObject



22
23
24
# File 'app/models/status.rb', line 22

def self.find_all
  @@statuses.dup
end

.selectableObject



26
27
28
# File 'app/models/status.rb', line 26

def self.selectable
  find_all - [self['Scheduled']]
end

.selectable_valuesObject



30
31
32
# File 'app/models/status.rb', line 30

def self.selectable_values
  selectable.map(&:name)
end

Instance Method Details

#symbolObject



10
11
12
# File 'app/models/status.rb', line 10

def symbol
  @name.to_s.downcase.intern
end