Class: Hudu::AssetHelper
- Inherits:
-
Object
- Object
- Hudu::AssetHelper
- Defined in:
- lib/hudu/asset_helper.rb
Overview
The AssetHelper class contains helper methods for constructing and creating asset data.
Class Method Summary collapse
-
.construct_asset(asset) ⇒ Hash
Constructs an asset for updates by extracting key attributes and formatting custom fields.
-
.create_asset(name, asset_layout_id, fields) ⇒ Hash
Creates a new asset from the given layout and fields.
-
.custom_fields(fields) ⇒ Array<Hash>
Formats custom fields into a standardized hash structure.
Class Method Details
.construct_asset(asset) ⇒ Hash
Constructs an asset for updates by extracting key attributes and formatting custom fields.
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/hudu/asset_helper.rb', line 15 def self.construct_asset(asset) custom_asset = asset.attributes.slice(*%w[ id company_id asset_layout_id slug name primary_serial primary_model primary_mail primary_manufacturer ] ) custom_asset['custom_fields'] = custom_fields(asset.fields) { asset: custom_asset } end |
.create_asset(name, asset_layout_id, fields) ⇒ Hash
Creates a new asset from the given layout and fields.
37 38 39 40 41 42 43 44 45 |
# File 'lib/hudu/asset_helper.rb', line 37 def self.create_asset(name, asset_layout_id, fields) { asset: { name: name, asset_layout_id: asset_layout_id, custom_fields: custom_fields(fields) } } end |
.custom_fields(fields) ⇒ Array<Hash>
Formats custom fields into a standardized hash structure.
56 57 58 |
# File 'lib/hudu/asset_helper.rb', line 56 def self.custom_fields(fields) [fields.map { |field| [field.label.downcase.gsub(' ', '_'), field.value] }.to_h] end |