Class: Wukong::FlatPack::Tokens::FixedPointToken

Inherits:
Token
  • Object
show all
Defined in:
lib/wukong/model/flatpack_parser/tokens.rb

Instance Attribute Summary collapse

Attributes inherited from Token

#indicator, #length, #position

Instance Method Summary collapse

Methods inherited from Token

indicator=

Instance Attribute Details

#powerObject

Returns the value of attribute power.



22
23
24
# File 'lib/wukong/model/flatpack_parser/tokens.rb', line 22

def power
  @power
end

#strictObject

Returns the value of attribute strict.



23
24
25
# File 'lib/wukong/model/flatpack_parser/tokens.rb', line 23

def strict
  @strict
end

Instance Method Details

#reObject

TODO: Allow negative powers



28
29
30
# File 'lib/wukong/model/flatpack_parser/tokens.rb', line 28

def re
  strict ? "(?:(?:\\+|-)\\d{#{@length-1}}|\\d{#{@length}})" : ".{#{@length}}"
end

#translate(str) ⇒ Object



32
33
34
35
36
# File 'lib/wukong/model/flatpack_parser/tokens.rb', line 32

def translate str
  return nil if str.strip == ""
  base = str.to_f
  return base / (10**@power)
end