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.
289 290 291 292 293 |
# File 'lib/fit4ruby/GlobalFitMessage.rb', line 289 def initialize(&block) @current_message = nil @messages = {} instance_eval(&block) if block_given? end |
Instance Method Details
#[](number) ⇒ Object
343 344 345 |
# File 'lib/fit4ruby/GlobalFitMessage.rb', line 343 def [](number) @messages[number] end |
#alt_field(number, ref_field, &block) ⇒ Object
336 337 338 339 340 341 |
# File 'lib/fit4ruby/GlobalFitMessage.rb', line 336 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
302 303 304 305 306 |
# File 'lib/fit4ruby/GlobalFitMessage.rb', line 302 def each @messages.each_value do || yield() end end |
#field(number, type, name, opts = {}) ⇒ Object
329 330 331 332 333 334 |
# File 'lib/fit4ruby/GlobalFitMessage.rb', line 329 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
325 326 327 |
# File 'lib/fit4ruby/GlobalFitMessage.rb', line 325 def find_by_name(name) @messages.values.find { |m| m.name == name } end |
#message(number, name) ⇒ Object
295 296 297 298 299 300 |
# File 'lib/fit4ruby/GlobalFitMessage.rb', line 295 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
308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 |
# File 'lib/fit4ruby/GlobalFitMessage.rb', line 308 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 |