Class: FriendlyShipping::PackageOptions
- Inherits:
-
Object
- Object
- FriendlyShipping::PackageOptions
- Defined in:
- lib/friendly_shipping/package_options.rb
Overview
Base class for package options. Used when serializing API requests.
Direct Known Subclasses
Services::RL::PackageOptions, Services::ShipEngine::LabelPackageOptions, Services::ShipEngine::RatesPackageOptions, Services::ShipEngineLTL::PackageOptions, Services::TForceFreight::PackageOptions, Services::USPSShip::RateEstimatePackageOptions, Services::Ups::LabelPackageOptions, Services::Ups::RateEstimatePackageOptions, Services::UpsFreight::RatesPackageOptions, Services::UpsJson::LabelPackageOptions, Services::UpsJson::RatesPackageOptions, Services::Usps::RateEstimatePackageOptions, Services::UspsInternational::RateEstimatePackageOptions
Instance Attribute Summary collapse
-
#package_id ⇒ String
readonly
The ID for the package that belongs to these options.
Instance Method Summary collapse
-
#initialize(package_id:, item_options: Set.new, item_options_class: ItemOptions) ⇒ PackageOptions
constructor
A new instance of PackageOptions.
-
#options_for_item(item) ⇒ ItemOptions
Finds and returns item options for the given item.
Constructor Details
#initialize(package_id:, item_options: Set.new, item_options_class: ItemOptions) ⇒ PackageOptions
Returns a new instance of PackageOptions.
12 13 14 15 16 17 18 19 20 |
# File 'lib/friendly_shipping/package_options.rb', line 12 def initialize( package_id:, item_options: Set.new, item_options_class: ItemOptions ) @package_id = package_id @item_options = @item_options_class = end |
Instance Attribute Details
#package_id ⇒ String (readonly)
Returns the ID for the package that belongs to these options.
7 8 9 |
# File 'lib/friendly_shipping/package_options.rb', line 7 def package_id @package_id end |
Instance Method Details
#options_for_item(item) ⇒ ItemOptions
Finds and returns item options for the given item. If options cannot be
found, the item_options_class
is used to construct new options.
27 28 29 30 31 |
# File 'lib/friendly_shipping/package_options.rb', line 27 def (item) .detect do |item_option| item_option.item_id == item.id end || .new(item_id: nil) end |