Class: ViewComponent::Storybook::Controls::Number
- Inherits:
-
SimpleControl
- Object
- Control
- SimpleControl
- ViewComponent::Storybook::Controls::Number
- Defined in:
- lib/view_component/storybook/controls/number.rb
Constant Summary collapse
- TYPES =
%i[number range].freeze
Instance Attribute Summary collapse
-
#max ⇒ Object
readonly
Returns the value of attribute max.
-
#min ⇒ Object
readonly
Returns the value of attribute min.
-
#step ⇒ Object
readonly
Returns the value of attribute step.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Attributes inherited from Control
#default, #description, #name, #param
Instance Method Summary collapse
-
#initialize(param, type:, default: nil, min: nil, max: nil, step: nil, name: nil, description: nil, **opts) ⇒ Number
constructor
A new instance of Number.
- #parse_param_value(value) ⇒ Object
Methods inherited from SimpleControl
Methods inherited from Control
Constructor Details
#initialize(param, type:, default: nil, min: nil, max: nil, step: nil, name: nil, description: nil, **opts) ⇒ Number
Returns a new instance of Number.
14 15 16 17 18 19 20 |
# File 'lib/view_component/storybook/controls/number.rb', line 14 def initialize(param, type:, default: nil, min: nil, max: nil, step: nil, name: nil, description: nil, **opts) super(param, default: default, name: name, description: description, **opts) @type = type @min = min @max = max @step = step end |
Instance Attribute Details
#max ⇒ Object (readonly)
Returns the value of attribute max.
9 10 11 |
# File 'lib/view_component/storybook/controls/number.rb', line 9 def max @max end |
#min ⇒ Object (readonly)
Returns the value of attribute min.
9 10 11 |
# File 'lib/view_component/storybook/controls/number.rb', line 9 def min @min end |
#step ⇒ Object (readonly)
Returns the value of attribute step.
9 10 11 |
# File 'lib/view_component/storybook/controls/number.rb', line 9 def step @step end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
9 10 11 |
# File 'lib/view_component/storybook/controls/number.rb', line 9 def type @type end |
Instance Method Details
#parse_param_value(value) ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/view_component/storybook/controls/number.rb', line 22 def parse_param_value(value) if value.is_a?(String) && value.present? (value.to_f % 1) > 0 ? value.to_f : value.to_i else value end end |