Class: ActiveSet::EnumerableSetInstruction

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
lib/active_set/enumerable_set_instruction.rb

Direct Known Subclasses

Filtering::Enumerable::SetInstruction

Instance Method Summary collapse

Constructor Details

#initialize(attribute_instruction, set) ⇒ EnumerableSetInstruction

Returns a new instance of EnumerableSetInstruction.



5
6
7
8
9
# File 'lib/active_set/enumerable_set_instruction.rb', line 5

def initialize(attribute_instruction, set)
  @attribute_instruction = attribute_instruction
  @set = set
  super(@attribute_instruction)
end

Instance Method Details

#attribute_value_for(item) ⇒ Object



11
12
13
14
15
16
17
18
19
# File 'lib/active_set/enumerable_set_instruction.rb', line 11

def attribute_value_for(item)
  @item_values ||= Hash.new do |h, key|
    item_value = @attribute_instruction.value_for(item: key)
    item_value = item_value.downcase if case_insensitive_operation_for?(item_value)
    h[key] = item_value
  end

  @item_values[item]
end

#case_insensitive_operation_for?(value) ⇒ Boolean

Returns:

  • (Boolean)


29
30
31
32
33
# File 'lib/active_set/enumerable_set_instruction.rb', line 29

def case_insensitive_operation_for?(value)
  return false unless @attribute_instruction.case_insensitive?

  value.is_a?(String) || value.is_a?(Symbol)
end

#instruction_valueObject



21
22
23
24
25
26
27
# File 'lib/active_set/enumerable_set_instruction.rb', line 21

def instruction_value
  return @instruction_value if defined? @instruction_value

  instruction_value = @attribute_instruction.value
  instruction_value = instruction_value.downcase if case_insensitive_operation_for?(instruction_value)
  @instruction_value = instruction_value
end