module BinaryParser::BuiltInTemplate

Constants

BCD
BCD_f1
BCD_f10
BCD_f2
BCD_f3
BCD_f4
BCD_f5
BCD_f6
BCD_f7
BCD_f8
BCD_f9

Public Class Methods

bcd_make(floating_point) click to toggle source
# File lib/binary_parser/built_in_template/bcd.rb, line 3
def self.bcd_make(floating_point)
  klass = Class.new(TemplateBase) do
    Def do
      SPEND rest, :decimals, UInt4
    end

    def self.floating_point
      @floating_point
    end

    def floating_point
      self.class.floating_point
    end

    def to_i
      decimals.inject(0){|acc, n| acc * 10 + n.to_i}
    end

    def to_s
      return to_i.to_s if floating_point == 0
      to_i.to_s.insert(-(floating_point + 1), ".")
    end

    def to_f
      to_s.to_f
    end

    def content_description
      to_s
    end
  end
  
  klass.instance_variable_set(:@floating_point, floating_point)
  return klass
end
floating_point() click to toggle source
# File lib/binary_parser/built_in_template/bcd.rb, line 9
def self.floating_point
  @floating_point
end

Public Instance Methods

content_description() click to toggle source
# File lib/binary_parser/built_in_template/bcd.rb, line 30
def content_description
  to_s
end
floating_point() click to toggle source
# File lib/binary_parser/built_in_template/bcd.rb, line 13
def floating_point
  self.class.floating_point
end
to_f() click to toggle source
# File lib/binary_parser/built_in_template/bcd.rb, line 26
def to_f
  to_s.to_f
end
to_i() click to toggle source
# File lib/binary_parser/built_in_template/bcd.rb, line 17
def to_i
  decimals.inject(0){|acc, n| acc * 10 + n.to_i}
end
to_s() click to toggle source
# File lib/binary_parser/built_in_template/bcd.rb, line 21
def to_s
  return to_i.to_s if floating_point == 0
  to_i.to_s.insert(-(floating_point + 1), ".")
end