Class: Sandals::Select
- Inherits:
-
Object
- Object
- Sandals::Select
- Includes:
- Actionable, FieldValidation
- Defined in:
- lib/sandals/view.rb
Direct Known Subclasses
Defined Under Namespace
Classes: Option
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#label ⇒ Object
readonly
Returns the value of attribute label.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Attributes included from FieldValidation
Instance Method Summary collapse
- #change(value) ⇒ Object
-
#initialize(id, label, options:, value:, action:, error: nil) ⇒ Select
constructor
A new instance of Select.
- #selected?(option) ⇒ Boolean
Methods included from FieldValidation
Constructor Details
#initialize(id, label, options:, value:, action:, error: nil) ⇒ Select
Returns a new instance of Select.
435 436 437 438 439 440 441 442 443 |
# File 'lib/sandals/view.rb', line 435 def initialize(id, label, options:, value:, action:, error: nil) @id = id @label = label.to_s @options = normalize() @value = value initialize_error(error) @action = action validate_unique_values end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
433 434 435 |
# File 'lib/sandals/view.rb', line 433 def id @id end |
#label ⇒ Object (readonly)
Returns the value of attribute label.
433 434 435 |
# File 'lib/sandals/view.rb', line 433 def label @label end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
433 434 435 |
# File 'lib/sandals/view.rb', line 433 def @options end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
433 434 435 |
# File 'lib/sandals/view.rb', line 433 def value @value end |
Instance Method Details
#change(value) ⇒ Object
445 446 447 448 449 450 |
# File 'lib/sandals/view.rb', line 445 def change(value) option = @options.find { |candidate| candidate.value.to_s == value } raise ArgumentError, "unknown select value: #{value}" unless option execute_action(option.value) end |
#selected?(option) ⇒ Boolean
452 453 454 |
# File 'lib/sandals/view.rb', line 452 def selected?(option) option.value == value end |