Class: Fit4Ruby::GlobalFitMessageList
- Inherits:
-
Object
- Object
- Fit4Ruby::GlobalFitMessageList
- Defined in:
- lib/fit4ruby/GlobalFitMessage.rb
Instance Method Summary collapse
- #[](number) ⇒ 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.
135 136 137 138 139 |
# File 'lib/fit4ruby/GlobalFitMessage.rb', line 135 def initialize(&block) = nil = {} instance_eval(&block) if block_given? end |
Instance Method Details
#[](number) ⇒ Object
182 183 184 |
# File 'lib/fit4ruby/GlobalFitMessage.rb', line 182 def [](number) [number] end |
#each ⇒ Object
148 149 150 151 152 |
# File 'lib/fit4ruby/GlobalFitMessage.rb', line 148 def each .each_value do || yield() end end |
#field(number, type, name, opts = {}) ⇒ Object
175 176 177 178 179 180 |
# File 'lib/fit4ruby/GlobalFitMessage.rb', line 175 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
171 172 173 |
# File 'lib/fit4ruby/GlobalFitMessage.rb', line 171 def find_by_name(name) .each_value{ |m| return m if m.name == name } end |
#message(number, name) ⇒ Object
141 142 143 144 145 146 |
# File 'lib/fit4ruby/GlobalFitMessage.rb', line 141 def (number, name) if .include?(number) raise "Message #{number} has already been defined" end [number] = = GlobalFitMessage.new(name, number) end |
#write(io) ⇒ Object
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
# File 'lib/fit4ruby/GlobalFitMessage.rb', line 154 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 |