Class: TestPack1::Device

Inherits:
BaseModel show all
Defined in:
lib/test_pack_1/models/device.rb

Overview

Device Model.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

#to_hash, #to_json

Constructor Details

#initialize(device_id = nil, title = nil, alt_title = nil, identity = nil, site = nil, device_type = nil, device_type_id = nil, parent_id = nil, child_ids = nil, device_model = nil, turbine_type = nil, max_power = nil, bidding_area = nil, timestamp_start = nil, latitude = nil, longitude = nil, elevation = nil, target_availability = nil, metadata = nil) ⇒ Device

Returns a new instance of Device.



111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# File 'lib/test_pack_1/models/device.rb', line 111

def initialize(device_id = nil,
               title = nil,
               alt_title = nil,
               identity = nil,
               site = nil,
               device_type = nil,
               device_type_id = nil,
               parent_id = nil,
               child_ids = nil,
               device_model = nil,
               turbine_type = nil,
               max_power = nil,
               bidding_area = nil,
               timestamp_start = nil,
               latitude = nil,
               longitude = nil,
               elevation = nil,
               target_availability = nil,
                = nil)
  @device_id = device_id
  @title = title
  @alt_title = alt_title
  @identity = identity
  @site = site
  @device_type = device_type
  @device_type_id = device_type_id
  @parent_id = parent_id
  @child_ids = child_ids
  @device_model = device_model
  @turbine_type = turbine_type
  @max_power = max_power
  @bidding_area = bidding_area
  @timestamp_start = timestamp_start
  @latitude = latitude
  @longitude = longitude
  @elevation = elevation
  @target_availability = target_availability
   = 
end

Instance Attribute Details

#alt_titleString

An alternative title.

Returns:



20
21
22
# File 'lib/test_pack_1/models/device.rb', line 20

def alt_title
  @alt_title
end

#bidding_areaString

Only applies to Nordic countries and the UK.

Returns:



60
61
62
# File 'lib/test_pack_1/models/device.rb', line 60

def bidding_area
  @bidding_area
end

#child_idsList of Integer

Ids of child devices, if any.

Returns:

  • (List of Integer)


44
45
46
# File 'lib/test_pack_1/models/device.rb', line 44

def child_ids
  @child_ids
end

#device_idInteger

The id of a device.

Returns:

  • (Integer)


12
13
14
# File 'lib/test_pack_1/models/device.rb', line 12

def device_id
  @device_id
end

#device_modelDeviceModel

General device model information.

Returns:



48
49
50
# File 'lib/test_pack_1/models/device.rb', line 48

def device_model
  @device_model
end

#device_typeString

The string representation of the device type.

Returns:



32
33
34
# File 'lib/test_pack_1/models/device.rb', line 32

def device_type
  @device_type
end

#device_type_idInteger

The id of a device type.

Returns:

  • (Integer)


36
37
38
# File 'lib/test_pack_1/models/device.rb', line 36

def device_type_id
  @device_type_id
end

#elevationString

The elevation of the device in meters above sea level.

Returns:



76
77
78
# File 'lib/test_pack_1/models/device.rb', line 76

def elevation
  @elevation
end

#identityString

Device identification number.

Returns:



24
25
26
# File 'lib/test_pack_1/models/device.rb', line 24

def identity
  @identity
end

#latitudeString

The latitude of the device in the WGS84 system.

Returns:



68
69
70
# File 'lib/test_pack_1/models/device.rb', line 68

def latitude
  @latitude
end

#longitudeString

The longitude of the device in the WGS84 system.

Returns:



72
73
74
# File 'lib/test_pack_1/models/device.rb', line 72

def longitude
  @longitude
end

#max_powerInteger

The maximum power for a device.

Returns:

  • (Integer)


56
57
58
# File 'lib/test_pack_1/models/device.rb', line 56

def max_power
  @max_power
end

#metadataList of MetadataField

A list of metadata fields and their values.

Returns:



84
85
86
# File 'lib/test_pack_1/models/device.rb', line 84

def 
  
end

#parent_idInteger

The id of the parent device, if any.

Returns:

  • (Integer)


40
41
42
# File 'lib/test_pack_1/models/device.rb', line 40

def parent_id
  @parent_id
end

#siteSite

Device identification number.

Returns:



28
29
30
# File 'lib/test_pack_1/models/device.rb', line 28

def site
  @site
end

#target_availabilityFloat

The target availability for the device.

Returns:

  • (Float)


80
81
82
# File 'lib/test_pack_1/models/device.rb', line 80

def target_availability
  @target_availability
end

#timestamp_startDateTime

The earliest timestamp device data is available for.

Returns:

  • (DateTime)


64
65
66
# File 'lib/test_pack_1/models/device.rb', line 64

def timestamp_start
  @timestamp_start
end

#titleString

The id of a device.

Returns:



16
17
18
# File 'lib/test_pack_1/models/device.rb', line 16

def title
  @title
end

#turbine_typeTurbineType

Turbine-specific type information.

Returns:



52
53
54
# File 'lib/test_pack_1/models/device.rb', line 52

def turbine_type
  @turbine_type
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
# File 'lib/test_pack_1/models/device.rb', line 152

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.

  device_id = hash['deviceId']
  title = hash['title']
  alt_title = hash['altTitle']
  identity = hash['identity']
  site = Site.from_hash(hash['site']) if hash['site']
  device_type = hash['deviceType']
  device_type_id = hash['deviceTypeId']
  parent_id = hash['parentId']
  child_ids = hash['childIds']
  device_model = DeviceModel.from_hash(hash['deviceModel']) if
    hash['deviceModel']
  turbine_type = TurbineType.from_hash(hash['turbineType']) if
    hash['turbineType']
  max_power = hash['maxPower']
  bidding_area = hash['biddingArea']
  timestamp_start = APIHelper.rfc3339(hash['timestampStart']) if
    hash['timestampStart']
  latitude = hash['latitude']
  longitude = hash['longitude']
  elevation = hash['elevation']
  target_availability = hash['targetAvailability']
  # Parameter is an array, so we need to iterate through it

   = nil
  unless hash['metadata'].nil?
     = []
    hash['metadata'].each do |structure|
       << (MetadataField.from_hash(structure) if structure)
    end
  end

  # Create object from extracted values.

  Device.new(device_id,
             title,
             alt_title,
             identity,
             site,
             device_type,
             device_type_id,
             parent_id,
             child_ids,
             device_model,
             turbine_type,
             max_power,
             bidding_area,
             timestamp_start,
             latitude,
             longitude,
             elevation,
             target_availability,
             )
end

.namesObject

A mapping from model property names to API property names.



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/test_pack_1/models/device.rb', line 87

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['device_id'] = 'deviceId'
  @_hash['title'] = 'title'
  @_hash['alt_title'] = 'altTitle'
  @_hash['identity'] = 'identity'
  @_hash['site'] = 'site'
  @_hash['device_type'] = 'deviceType'
  @_hash['device_type_id'] = 'deviceTypeId'
  @_hash['parent_id'] = 'parentId'
  @_hash['child_ids'] = 'childIds'
  @_hash['device_model'] = 'deviceModel'
  @_hash['turbine_type'] = 'turbineType'
  @_hash['max_power'] = 'maxPower'
  @_hash['bidding_area'] = 'biddingArea'
  @_hash['timestamp_start'] = 'timestampStart'
  @_hash['latitude'] = 'latitude'
  @_hash['longitude'] = 'longitude'
  @_hash['elevation'] = 'elevation'
  @_hash['target_availability'] = 'targetAvailability'
  @_hash['metadata'] = 'metadata'
  @_hash
end