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.
354 355 356 357 358 |
# File 'lib/fit4ruby/GlobalFitMessage.rb', line 354 def initialize(&block) @current_message = nil @messages = {} instance_eval(&block) if block_given? end |
Instance Method Details
#[](number) ⇒ Object
408 409 410 |
# File 'lib/fit4ruby/GlobalFitMessage.rb', line 408 def [](number) @messages[number] end |
#alt_field(number, ref_field, &block) ⇒ Object
401 402 403 404 405 406 |
# File 'lib/fit4ruby/GlobalFitMessage.rb', line 401 def alt_field(number, ref_field, &block) unless @current_message raise "You must define a message first" end @current_message.alt_field(number, ref_field, &block) end |
#each ⇒ Object
367 368 369 370 371 |
# File 'lib/fit4ruby/GlobalFitMessage.rb', line 367 def each @messages.each_value do || yield() end end |
#field(number, type, name, opts = {}) ⇒ Object
394 395 396 397 398 399 |
# File 'lib/fit4ruby/GlobalFitMessage.rb', line 394 def field(number, type, name, opts = {}) unless @current_message raise "You must define a message first" end @current_message.field(number, type, name, opts) end |
#find_by_name(name) ⇒ Object
390 391 392 |
# File 'lib/fit4ruby/GlobalFitMessage.rb', line 390 def find_by_name(name) @messages.values.find { |m| m.name == name } end |
#message(number, name) ⇒ Object
360 361 362 363 364 365 |
# File 'lib/fit4ruby/GlobalFitMessage.rb', line 360 def (number, name) if @messages.include?(number) raise "Message #{number} has already been defined" end @messages[number] = @current_message = GlobalFitMessage.new(name, number) end |
#write(io) ⇒ Object
373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 |
# File 'lib/fit4ruby/GlobalFitMessage.rb', line 373 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 @messages.length > 16 raise 'Cannot support more than 16 message types!' end = 0 @messages.each do |number, | .write(io, ) end end |