Class: SimplestStatus::Status
- Inherits:
-
Object
- Object
- SimplestStatus::Status
- Defined in:
- lib/simplest_status/status.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
- #==(status) ⇒ Object
- #constant_name ⇒ Object
- #for_select ⇒ Object
-
#initialize(input) ⇒ Status
constructor
A new instance of Status.
- #label ⇒ Object
- #matches?(input) ⇒ Boolean
- #string ⇒ Object (also: #to_s)
- #symbol ⇒ Object
- #to_hash ⇒ Object
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
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/simplest_status/status.rb', line 3 def name @name end |
#value ⇒ Object (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_name ⇒ Object
26 27 28 |
# File 'lib/simplest_status/status.rb', line 26 def constant_name string.upcase end |
#for_select ⇒ Object
34 35 36 |
# File 'lib/simplest_status/status.rb', line 34 def for_select [label, value] end |
#label ⇒ Object
30 31 32 |
# File 'lib/simplest_status/status.rb', line 30 def label string.split(/[\s_-]+/).map(&:capitalize).join(' ') end |
#matches?(input) ⇒ Boolean
22 23 24 |
# File 'lib/simplest_status/status.rb', line 22 def matches?(input) [string, value.to_s].include? input.to_s end |
#string ⇒ Object Also known as: to_s
13 14 15 |
# File 'lib/simplest_status/status.rb', line 13 def string name.to_s end |
#symbol ⇒ Object
9 10 11 |
# File 'lib/simplest_status/status.rb', line 9 def symbol name.to_sym end |
#to_hash ⇒ Object
18 19 20 |
# File 'lib/simplest_status/status.rb', line 18 def to_hash { name => value } end |