Class: SimplestStatus::Status

Inherits:
Object
  • Object
show all
Defined in:
lib/simplest_status/status.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input) ⇒ Status

Returns a new instance of Status.



5
6
7
# File 'lib/simplest_status/status.rb', line 5

def initialize(input)
  @name, @value = Array(input)
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/simplest_status/status.rb', line 3

def name
  @name
end

#valueObject (readonly)

Returns the value of attribute value.



3
4
5
# File 'lib/simplest_status/status.rb', line 3

def value
  @value
end

Instance Method Details

#==(status) ⇒ Object



38
39
40
# File 'lib/simplest_status/status.rb', line 38

def ==(status)
  self.to_hash == status.to_hash
end

#constant_nameObject



26
27
28
# File 'lib/simplest_status/status.rb', line 26

def constant_name
  string.upcase
end

#for_selectObject



34
35
36
# File 'lib/simplest_status/status.rb', line 34

def for_select
  [label, value]
end

#labelObject



30
31
32
# File 'lib/simplest_status/status.rb', line 30

def label
  string.split(/[\s_-]+/).map(&:capitalize).join(' ')
end

#matches?(input) ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/simplest_status/status.rb', line 22

def matches?(input)
  [string, value.to_s].include? input.to_s
end

#stringObject Also known as: to_s



13
14
15
# File 'lib/simplest_status/status.rb', line 13

def string
  name.to_s
end

#symbolObject



9
10
11
# File 'lib/simplest_status/status.rb', line 9

def symbol
  name.to_sym
end

#to_hashObject



18
19
20
# File 'lib/simplest_status/status.rb', line 18

def to_hash
  { name => value }
end