Class: Fit::File::Definition::Field

Inherits:
BinData::Record
  • Object
show all
Defined in:
lib/fit/file/definition.rb

Instance Method Summary collapse

Instance Method Details

#dataObject



14
15
16
17
18
# File 'lib/fit/file/definition.rb', line 14

def data
  @data ||= Definitions.get_field(parent.parent.global_message_number.snapshot,
                                  field_definition_number.snapshot) ||
              { :name => "field_#{field_definition_number.snapshot}", :scale => nil }
end

#nameObject



20
21
22
# File 'lib/fit/file/definition.rb', line 20

def name
  data[:name]
end

#raw_nameObject



24
25
26
# File 'lib/fit/file/definition.rb', line 24

def raw_name
  "raw_#{name}"
end

#scaleObject



28
29
30
# File 'lib/fit/file/definition.rb', line 28

def scale
  data[:scale]
end

#typeObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/fit/file/definition.rb', line 32

def type
  case base_type_number.snapshot
  when 0 # enum
    build_int_type 8, false
  when 1
    build_int_type 8, true
  when 2
    build_int_type 8, false
  when 3
    build_int_type 16, true
  when 4
    build_int_type 16, false
  when 5
    build_int_type 32, true
  when 6
    build_int_type 32, false
  when 7
    "stringz"
  when 8
    "float"
  when 9
    "double"
  when 10 # uint8z
    build_int_type 8, false
  when 11 # uint16z
    build_int_type 16, false
  when 12 # uint32z
    build_int_type 32, false
  when 13 # array of bytes
    build_int_type 8, false
  else
    raise "Can't map base_type_number #{base_type_number} to a data type"
  end
end