class PIM::OptionList

Attributes

model_defined[RW]
name[RW]
options[RW]

Public Class Methods

new(name, options, groups, service = nil) click to toggle source
# File pim.rb, line 4012
def initialize name, options, groups, service = nil
  @name = name
  if not service.nil?
    @service = service
    @options = nil
    @groups = nil
  else
    @service = nil
    @options = options
    if groups.nil?
      @groups = nil
    else
      @groups = {}
      groups.each_pair do |name, options|
        create_group name, options
      end
    end
  end
end
options_from_array(array) click to toggle source
# File pim.rb, line 4000
def self.options_from_array array
  array = array.map { |v| [v, v] }
  self.options_from_hash array
end
options_from_hash(hash) click to toggle source
# File pim.rb, line 4005
def self.options_from_hash hash
  hash = Hash[hash.map { |k, v| [PIM.to_sym(k), v.to_s] }]
  hash
end
to_options(*args) click to toggle source
# File pim.rb, line 3990
def self.to_options *args
  args = PIM.compact_args(*args)
  if PIM.is_hash?(args)
    return self.options_from_hash args
  elsif PIM.is_array?(args)
    return self.options_from_array args
  end
  self.options_from_array args
end

Public Instance Methods

as_json(opts = {}) click to toggle source
# File pim.rb, line 4082
def as_json opts = {}
  hash = {
    :name => @name.to_s,
    :options => to_key_value_list(@options)
  }
  hash[:serviceName] = PIM.get_service_name(@service) unless @service.nil?
  hash[:groups] = @groups unless is_empty?(@groups)
  hash
end
group(group_name, *options) click to toggle source
# File pim.rb, line 4055
def group group_name, *options
  group_name = to_sym(group_name)
  @groups[group_name]
end
groups(*group_names) click to toggle source
# File pim.rb, line 4060
def groups *group_names
  if group_names.empty?
    @groups
  else
    group_names = symbolized_array(group_names)
    @groups.select { |name| group_names.include?(name) }
  end
end
includes_option?(option, *group_names) click to toggle source
# File pim.rb, line 4069
def includes_option? option, *group_names

  return false if !PIM.includes_value?(option, @options)
  return true if group_names.empty?
  return false if @groups.empty?

  groups(*group_names).each_value do |group|
    return true if PIM.includes_value?(option, group)
  end

  return false
end
service() click to toggle source
# File pim.rb, line 4051
def service
  return @service
end