Class: ConvenientService::Config::Entities::OptionCollection

Inherits:
Object
  • Object
show all
Defined in:
lib/convenient_service/config/entities/option_collection.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options: {}) ⇒ void

Parameters:



29
30
31
# File 'lib/convenient_service/config/entities/option_collection.rb', line 29

def initialize(options: {})
  @options = options
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



20
21
22
# File 'lib/convenient_service/config/entities/option_collection.rb', line 20

def options
  @options
end

Instance Method Details

#==(other) ⇒ Boolean?

Parameters:

  • other (Object)

    Can be any type.

Returns:

  • (Boolean, nil)


124
125
126
127
128
129
130
# File 'lib/convenient_service/config/entities/option_collection.rb', line 124

def ==(other)
  return unless other.instance_of?(self.class)

  return false if options != other.options

  true
end

#[](name) ⇒ Boolean

Parameters:

  • name (Symbol)

Returns:

  • (Boolean)


67
68
69
# File 'lib/convenient_service/config/entities/option_collection.rb', line 67

def [](name)
  options[name]
end

#any?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/convenient_service/config/entities/option_collection.rb', line 46

def any?
  options.any? { |_name, option| option.enabled? }
end

#dupConvenientService::Config::Entities::OptionCollection



77
78
79
# File 'lib/convenient_service/config/entities/option_collection.rb', line 77

def dup
  self.class.new(options: options.dup)
end

#include?(name) ⇒ Boolean

Parameters:

  • name (Symbol)

Returns:

  • (Boolean)


57
58
59
60
61
# File 'lib/convenient_service/config/entities/option_collection.rb', line 57

def include?(name)
  return false unless options.has_key?(name)

  options[name].enabled?
end

#keysArray<Symbol>

Returns:

  • (Array<Symbol>)


36
37
38
# File 'lib/convenient_service/config/entities/option_collection.rb', line 36

def keys
  options.keys
end

#merge(other_options) ⇒ ConvenientService::Config::Entities::OptionCollection

Parameters:

  • other_options (Object)

    Can be any type.

Returns:



88
89
90
91
92
# File 'lib/convenient_service/config/entities/option_collection.rb', line 88

def merge(other_options)
  options.merge!(Commands::NormalizeOptions[options: other_options].to_h)

  self
end

#replace(other_options) ⇒ ConvenientService::Config::Entities::OptionCollection

Parameters:

  • other_options (Object)

    Can be any type.

Returns:



114
115
116
117
118
# File 'lib/convenient_service/config/entities/option_collection.rb', line 114

def replace(other_options)
  options.replace(Commands::NormalizeOptions[options: other_options].to_h)

  self
end

#subtract(other_options) ⇒ ConvenientService::Config::Entities::OptionCollection

Parameters:

  • other_options (Object)

    Can be any type.

Returns:



101
102
103
104
105
# File 'lib/convenient_service/config/entities/option_collection.rb', line 101

def subtract(other_options)
  Commands::NormalizeOptions[options: other_options].to_h.each_key { |name| options.delete(name) }

  self
end

#to_aArray<ConvenientService::Config::Entities::Option>



135
136
137
# File 'lib/convenient_service/config/entities/option_collection.rb', line 135

def to_a
  options.values
end

#to_hHash{Symbol => ConvenientService::Config::Entities::Option}

Returns:



142
143
144
# File 'lib/convenient_service/config/entities/option_collection.rb', line 142

def to_h
  options
end