Class: Wukong::FlatPack::Tokens::FixedPointToken
- Defined in:
- lib/wukong/model/flatpack_parser/tokens.rb
Instance Attribute Summary collapse
-
#power ⇒ Object
Returns the value of attribute power.
-
#strict ⇒ Object
Returns the value of attribute strict.
Attributes inherited from Token
#indicator, #length, #position
Instance Method Summary collapse
-
#re ⇒ Object
TODO: Allow negative powers.
- #translate(str) ⇒ Object
Methods inherited from Token
Instance Attribute Details
#power ⇒ Object
Returns the value of attribute power.
22 23 24 |
# File 'lib/wukong/model/flatpack_parser/tokens.rb', line 22 def power @power end |
#strict ⇒ Object
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
#re ⇒ Object
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 |