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.
413 414 415 416 417 418 419 420 421 |
# File 'lib/sandals/view.rb', line 413 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.
411 412 413 |
# File 'lib/sandals/view.rb', line 411 def id @id end |
#label ⇒ Object (readonly)
Returns the value of attribute label.
411 412 413 |
# File 'lib/sandals/view.rb', line 411 def label @label end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
411 412 413 |
# File 'lib/sandals/view.rb', line 411 def @options end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
411 412 413 |
# File 'lib/sandals/view.rb', line 411 def value @value end |
Instance Method Details
#change(value) ⇒ Object
423 424 425 426 427 428 |
# File 'lib/sandals/view.rb', line 423 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
430 431 432 |
# File 'lib/sandals/view.rb', line 430 def selected?(option) option.value == value end |