Class: SoftLayer::ProductItemCategory
- 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
Instance Method Summary collapse
-
#categoryCode ⇒ Object
:attr_reader: The categoryCode is a primary identifier for a particular category.
-
#default_option ⇒ Object
If the category has a single option (regardless of fees) this method will return that option.
-
#initialize(softlayer_client, network_hash, is_required) ⇒ ProductItemCategory
constructor
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. -
#name ⇒ Object
:attr_reader: The name of a category is a friendly, readable string.
-
#required? ⇒ Boolean
Returns true if this category is required in its package.
- #service ⇒ Object
Methods included from DynamicAttribute
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.
114 115 116 117 |
# File 'lib/softlayer/ProductItemCategory.rb', line 114 def initialize(softlayer_client, network_hash, is_required) super(softlayer_client, network_hash) @is_required = is_required end |
Instance Method Details
#categoryCode ⇒ Object
:attr_reader: The categoryCode is a primary identifier for a particular category. It is a string like ‘os’ or ‘ram’
53 |
# File 'lib/softlayer/ProductItemCategory.rb', line 53 sl_attr :categoryCode |
#default_option ⇒ Object
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.
103 104 105 106 107 108 109 |
# File 'lib/softlayer/ProductItemCategory.rb', line 103 def default_option if .count == 1 .first else .find { |option| option.free? } end end |
#name ⇒ Object
:attr_reader: The name of a category is a friendly, readable string
58 |
# File 'lib/softlayer/ProductItemCategory.rb', line 58 sl_attr :name |
#required? ⇒ Boolean
Returns true if this category is required in its package
120 121 122 |
# File 'lib/softlayer/ProductItemCategory.rb', line 120 def required?() return @is_required end |
#service ⇒ Object
86 87 88 |
# File 'lib/softlayer/ProductItemCategory.rb', line 86 def service softlayer_client[:SoftLayer_Product_Item_Category].object_with_id(self.id) end |