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.
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/hudu/asset_helper.rb', line 18 def self.construct_asset(asset) custom_asset = asset.attributes.slice( *%w[ asset_layout_id name primary_serial primary_model primary_mail primary_manufacturer ] ) custom_asset['custom_fields'] = custom_fields(asset.fields) custom_asset end |
.create_asset(name, asset_layout_id, fields) ⇒ Hash
Creates a new asset from the given layout and fields.
41 42 43 44 45 46 47 48 49 |
# File 'lib/hudu/asset_helper.rb', line 41 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.
61 62 63 |
# File 'lib/hudu/asset_helper.rb', line 61 def self.custom_fields(fields) fields.map { |field| { field.label.downcase.gsub(' ', '_') => field.value.to_s } } end |