Class: Coupdoeil::Hovercard::OptionsSet

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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 = {})
  @options = options
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



17
18
19
# File 'app/models/coupdoeil/hovercard/options_set.rb', line 17

def options
  @options
end

Instance Method Details

#custom_animation?Boolean

Returns:

  • (Boolean)


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

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

#dupObject



19
# File 'app/models/coupdoeil/hovercard/options_set.rb', line 19

def dup = OptionsSet.new(options.deep_dup)

#merge(options_set) ⇒ Object



28
29
30
# File 'app/models/coupdoeil/hovercard/options_set.rb', line 28

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

#preload?Boolean

Returns:

  • (Boolean)


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

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

#to_base36Object



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_hObject



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

def to_h = options

#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