Class: Coupdoeil::Popover::Option::Placement
- Inherits:
-
Coupdoeil::Popover::Option
- Object
- Coupdoeil::Popover::Option
- Coupdoeil::Popover::Option::Placement
- Defined in:
- app/models/coupdoeil/popover/option/placement.rb
Constant Summary collapse
- VALUES =
%w[ auto top top-start top-end right right-start right-end bottom bottom-start bottom-end left left-start left-end ].freeze
- INDEX_BY_VALUES =
VALUES.each_with_index.to_h.with_indifferent_access.freeze
Constants inherited from Coupdoeil::Popover::Option
Instance Attribute Summary
Attributes inherited from Coupdoeil::Popover::Option
Class Method Summary collapse
Instance Method Summary collapse
Methods inherited from Coupdoeil::Popover::Option
inherited, #initialize, into_bits
Constructor Details
This class inherits a constructor from Coupdoeil::Popover::Option
Class Method Details
.parse(value) ⇒ Object
19 20 21 22 23 24 25 26 27 28 |
# File 'app/models/coupdoeil/popover/option/placement.rb', line 19 def parse(value) values = value.to_s.split(",") 4.times.sum do |index| next 0 unless (placement = values[index]) placement.strip! placement_index = INDEX_BY_VALUES[placement] placement_index << (index * 4) end end |
Instance Method Details
#validate! ⇒ Object
31 32 33 34 35 36 37 38 39 40 |
# File 'app/models/coupdoeil/popover/option/placement.rb', line 31 def validate! values = value.to_s.split(",") values.each do |placement_value| next if placement_value.strip.in?(VALUES) values_sentence = VALUES.to_sentence(last_word_connector: " or ") raise_invalid_option "Value must be one of: #{values_sentence}" end end |