Class: SoftLayer::ProductItemCategory

Inherits:
ModelBase
  • Object
show all
Includes:
DynamicAttribute
Defined in:
lib/softlayer/ProductItemCategory.rb

Overview

The goal of this class is to make it easy for scripts (and scripters) to discover what product configuration options exist that can be added to a product order.

Instances of this class are created by and discovered in the context of a ProductPackage object. There should not be a need to create instances of this class directly.

This class roughly represents entities in the SoftLayer_Product_Item_Category service.

Instance Attribute Summary

Attributes inherited from ModelBase

#softlayer_client

Instance Method Summary collapse

Methods included from DynamicAttribute

included

Methods inherited from ModelBase

#[], #has_sl_property?, #refresh_details, sl_attr, #to_ary

Constructor Details

#initialize(softlayer_client, network_hash, is_required) ⇒ ProductItemCategory

The ProductItemCategory class augments the base initialization by accepting a boolean variable, is_required, which (when true) indicates that this category is required for orders against the package that created it.



148
149
150
151
# File 'lib/softlayer/ProductItemCategory.rb', line 148

def initialize(softlayer_client, network_hash, is_required)
  super(softlayer_client, network_hash)
  @is_required = is_required
end

Instance Method Details

#category_codeObject

:attr_reader: category_code The categoryCode is a primary identifier for a particular category. It is a string like ‘os’ or ‘ram’



74
# File 'lib/softlayer/ProductItemCategory.rb', line 74

sl_attr :category_code, 'categoryCode'

#categoryCodeObject

:attr_reader: The categoryCode is a primary identifier for a particular category. It is a string like ‘os’ or ‘ram’

DEPRECATION WARNING: This attribute is deprecated in favor of category_code and will be removed in the next major release.



83
# File 'lib/softlayer/ProductItemCategory.rb', line 83

sl_attr :categoryCode

#configuration_optionsObject

Retrieve the product item configuration information :call-seq:

configuration_options(force_update=false)


94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/softlayer/ProductItemCategory.rb', line 94

sl_dynamic_attr :configuration_options do |config_opts|
  config_opts.should_update? do
    # only retrieved once per instance
    @configuration_options == nil
  end

  config_opts.to_update do
    # This method assumes that the group and price item data was sent in
    # as part of the +network_hash+ used to initialize this object (as is done)
    # by the ProductPackage class. That class, in turn, gets its information
    # from SoftLayer_Product_Package::getCategories which does some complex
    # work on the back end to ensure the prices returned are correct.
    #
    # If this object was created in any other way, the configuration
    # options might be incorrect. So Caveat Emptor.
    #
    # Options are divided into groups (for convenience in the
    # web UI), but this code collapses the groups.
    self['groups'].collect do |group|
      group['prices'].sort{|lhs,rhs| lhs['sort'] <=> rhs['sort']}.collect do |price_item|
        ProductConfigurationOption.new(price_item['item'], price_item)
      end
    end.flatten # flatten out the individual group arrays.
  end
end

#default_optionObject

If the category has a single option (regardless of fees) this method will return that option. If the category has more than one option, this method will return the first that it finds with no fees associated with it.

If there are multiple options with no fees, it simply returns the first it finds

Note that the option found may NOT be the same default option that is given in the web-based ordering system.

If there are multiple options, and all of them have associated fees, then this method will return nil.



137
138
139
140
141
142
143
# File 'lib/softlayer/ProductItemCategory.rb', line 137

def default_option
  if configuration_options.count == 1
    configuration_options.first
  else
    configuration_options.find { |option| option.free? }
  end
end

#nameObject

:attr_reader: The name of a category is a friendly, readable string



88
# File 'lib/softlayer/ProductItemCategory.rb', line 88

sl_attr :name

#required?Boolean

Returns true if this category is required in its package

Returns:

  • (Boolean)


154
155
156
# File 'lib/softlayer/ProductItemCategory.rb', line 154

def required?()
  return @is_required
end

#serviceObject



120
121
122
# File 'lib/softlayer/ProductItemCategory.rb', line 120

def service
  softlayer_client[:SoftLayer_Product_Item_Category].object_with_id(self.id)
end