Class: Coupdoeil::Hovercard::OptionsSet
- Inherits:
-
Object
- Object
- Coupdoeil::Hovercard::OptionsSet
- Defined in:
- app/models/coupdoeil/hovercard/options_set.rb
Constant Summary collapse
- ORDERED_OPTIONS =
[ Option::Offset, Option::Placement, Option::Animation, Option::Cache, Option::Loading, Option::Trigger ].freeze
- OPTION_NAMES =
ORDERED_OPTIONS.map(&:key)
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #custom_animation? ⇒ Boolean
- #dup ⇒ Object
-
#initialize(options = {}) ⇒ OptionsSet
constructor
A new instance of OptionsSet.
- #merge(options_set) ⇒ Object
- #preload? ⇒ Boolean
- #to_base36 ⇒ Object
- #to_h ⇒ Object
- #validate! ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ OptionsSet
Returns a new instance of OptionsSet.
24 25 26 |
# File 'app/models/coupdoeil/hovercard/options_set.rb', line 24 def initialize( = {}) @options = end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
17 18 19 |
# File 'app/models/coupdoeil/hovercard/options_set.rb', line 17 def @options end |
Instance Method Details
#custom_animation? ⇒ Boolean
21 |
# File 'app/models/coupdoeil/hovercard/options_set.rb', line 21 def custom_animation? = [:animation].to_s == "custom" |
#dup ⇒ Object
19 |
# File 'app/models/coupdoeil/hovercard/options_set.rb', line 19 def dup = OptionsSet.new(.deep_dup) |
#merge(options_set) ⇒ Object
28 29 30 |
# File 'app/models/coupdoeil/hovercard/options_set.rb', line 28 def merge() OptionsSet.new(@options.merge(.)) end |
#preload? ⇒ Boolean
20 |
# File 'app/models/coupdoeil/hovercard/options_set.rb', line 20 def preload? = [:loading].to_s == "preload" |
#to_base36 ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 |
# File 'app/models/coupdoeil/hovercard/options_set.rb', line 42 def to_base36 @to_base36 ||= begin shift = 0 ORDERED_OPTIONS.reverse.sum do |option| bits = option.into_bits(@options[option.key]) result = bits << shift shift += option.bit_size result end.to_s(36).freeze end end |
#to_h ⇒ Object
22 |
# File 'app/models/coupdoeil/hovercard/options_set.rb', line 22 def to_h = |
#validate! ⇒ Object
32 33 34 35 36 37 38 39 40 |
# File 'app/models/coupdoeil/hovercard/options_set.rb', line 32 def validate! ORDERED_OPTIONS.map do |option| next unless @options.key?(option.key) value = @options[option.key] option.new(value).validate! end @options.assert_valid_keys(ORDERED_OPTIONS.map(&:key)) end |