Class: Coupdoeil::Popover::OptionsSet

Inherits:
Object
  • Object
show all
Defined in:
app/models/coupdoeil/popover/options_set.rb

Constant Summary collapse

ORDERED_OPTIONS =
[
  Option::Offset,
  Option::Placement,
  Option::Animation,
  Option::OpeningDelay,
  Option::Cache,
  Option::Loading,
  Option::Trigger
].freeze
OPTION_NAMES =
ORDERED_OPTIONS.map(&:key)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ OptionsSet

Returns a new instance of OptionsSet.



25
26
27
28
29
# File 'app/models/coupdoeil/popover/options_set.rb', line 25

def initialize(options = {})
  options.assert_valid_keys(OPTION_NAMES)

  @options = options
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



18
19
20
# File 'app/models/coupdoeil/popover/options_set.rb', line 18

def options
  @options
end

Instance Method Details

#custom_animation?Boolean

Returns:

  • (Boolean)


22
# File 'app/models/coupdoeil/popover/options_set.rb', line 22

def custom_animation? = options[:animation].to_s == "custom"

#dupObject



20
# File 'app/models/coupdoeil/popover/options_set.rb', line 20

def dup = OptionsSet.new(options.deep_dup)

#merge(options_set) ⇒ Object



31
32
33
# File 'app/models/coupdoeil/popover/options_set.rb', line 31

def merge(options_set)
  OptionsSet.new(options.merge(options_set.options))
end

#preload?Boolean

Returns:

  • (Boolean)


21
# File 'app/models/coupdoeil/popover/options_set.rb', line 21

def preload? = options[:loading].to_s == "preload"

#to_base36Object



48
49
50
51
52
53
54
55
56
57
58
# File 'app/models/coupdoeil/popover/options_set.rb', line 48

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_hObject



23
# File 'app/models/coupdoeil/popover/options_set.rb', line 23

def to_h = options

#validate!Object

no-op



45
46
47
48
49
50
51
52
# File 'app/models/coupdoeil/popover/options_set.rb', line 45

def validate!
  ORDERED_OPTIONS.map do |option|
    next unless options.key?(option.key)

    value = options[option.key]
    option.new(value).validate!
  end
end