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 rougly 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.



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

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

Instance Method Details

#categoryCodeObject

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



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

sl_attr :categoryCode

#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.



108
109
110
111
112
113
114
# File 'lib/softlayer/ProductItemCategory.rb', line 108

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



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

sl_attr :name

#required?Boolean

Returns true if this category is required in its package

Returns:

  • (Boolean)


125
126
127
# File 'lib/softlayer/ProductItemCategory.rb', line 125

def required?()
  return @is_required
end

#serviceObject



91
92
93
# File 'lib/softlayer/ProductItemCategory.rb', line 91

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