Class: Fit4Ruby::GlobalFitMessageList
- Inherits:
-
Object
- Object
- Fit4Ruby::GlobalFitMessageList
- Defined in:
- lib/fit4ruby/GlobalFitMessage.rb
Instance Method Summary collapse
- #[](number) ⇒ Object
- #alt_field(number, ref_field, &block) ⇒ Object
- #each ⇒ Object
- #field(number, type, name, opts = {}) ⇒ Object
- #find_by_name(name) ⇒ Object
-
#initialize(&block) ⇒ GlobalFitMessageList
constructor
A new instance of GlobalFitMessageList.
- #message(number, name) ⇒ Object
- #write(io) ⇒ Object
Constructor Details
#initialize(&block) ⇒ GlobalFitMessageList
Returns a new instance of GlobalFitMessageList.
284 285 286 287 288 |
# File 'lib/fit4ruby/GlobalFitMessage.rb', line 284 def initialize(&block) = nil = {} instance_eval(&block) if block_given? end |
Instance Method Details
#[](number) ⇒ Object
338 339 340 |
# File 'lib/fit4ruby/GlobalFitMessage.rb', line 338 def [](number) [number] end |
#alt_field(number, ref_field, &block) ⇒ Object
331 332 333 334 335 336 |
# File 'lib/fit4ruby/GlobalFitMessage.rb', line 331 def alt_field(number, ref_field, &block) unless raise "You must define a message first" end .alt_field(number, ref_field, &block) end |
#each ⇒ Object
297 298 299 300 301 |
# File 'lib/fit4ruby/GlobalFitMessage.rb', line 297 def each .each_value do || yield() end end |
#field(number, type, name, opts = {}) ⇒ Object
324 325 326 327 328 329 |
# File 'lib/fit4ruby/GlobalFitMessage.rb', line 324 def field(number, type, name, opts = {}) unless raise "You must define a message first" end .field(number, type, name, opts) end |
#find_by_name(name) ⇒ Object
320 321 322 |
# File 'lib/fit4ruby/GlobalFitMessage.rb', line 320 def find_by_name(name) .values.find { |m| m.name == name } end |
#message(number, name) ⇒ Object
290 291 292 293 294 295 |
# File 'lib/fit4ruby/GlobalFitMessage.rb', line 290 def (number, name) if .include?(number) raise "Message #{number} has already been defined" end [number] = = GlobalFitMessage.new(name, number) end |
#write(io) ⇒ Object
303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 |
# File 'lib/fit4ruby/GlobalFitMessage.rb', line 303 def write(io) # The FIT file supports more than 16 global message types. But only 16 # can be declared as local message types at any point of time. If there # are more then 16 messages, the current subset must be declared before # it's being used in the data records of the file. # Since we currently have 16 or less message types, we just write them # all upfront before the data records. if .length > 16 raise 'Cannot support more than 16 message types!' end = 0 .each do |number, | .write(io, ) end end |