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.
26 27 28 |
# File 'app/models/coupdoeil/hovercard/options_set.rb', line 26 def initialize( = {}) @options = end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
19 20 21 |
# File 'app/models/coupdoeil/hovercard/options_set.rb', line 19 def @options end |
Instance Method Details
#custom_animation? ⇒ Boolean
23 |
# File 'app/models/coupdoeil/hovercard/options_set.rb', line 23 def custom_animation? = [:animation].to_s == "custom" |
#dup ⇒ Object
21 |
# File 'app/models/coupdoeil/hovercard/options_set.rb', line 21 def dup = OptionsSet.new(.deep_dup) |
#merge(options_set) ⇒ Object
30 31 32 |
# File 'app/models/coupdoeil/hovercard/options_set.rb', line 30 def merge() OptionsSet.new(@options.merge(.)) end |
#preload? ⇒ Boolean
22 |
# File 'app/models/coupdoeil/hovercard/options_set.rb', line 22 def preload? = [:loading] == :preload |
#to_base36 ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 |
# File 'app/models/coupdoeil/hovercard/options_set.rb', line 44 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
24 |
# File 'app/models/coupdoeil/hovercard/options_set.rb', line 24 def to_h = |
#validate! ⇒ Object
34 35 36 37 38 39 40 41 42 |
# File 'app/models/coupdoeil/hovercard/options_set.rb', line 34 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 |