Class: Wukong::FlatPack::Tokens::IntToken

Inherits:
BasicToken show all
Defined in:
lib/wukong/model/flatpack_parser/tokens.rb

Constant Summary collapse

RE =
'(?:\+|-)?\\d'

Instance Attribute Summary

Attributes inherited from BasicToken

#modifier

Attributes inherited from Token

#indicator, #length, #position

Instance Method Summary collapse

Methods inherited from Token

indicator=

Instance Method Details

#reObject



58
59
60
61
62
63
64
65
66
# File 'lib/wukong/model/flatpack_parser/tokens.rb', line 58

def re
  if not @length.nil?
    return "(?:(?:\\+|-)\\d{#{@length-1}}|\\d{#{@length}})"
  elsif not @modifier.nil?
    return "#{RE}#{@modifier}"
  else
    return RE
  end
end

#translate(str) ⇒ Object



68
69
70
71
72
# File 'lib/wukong/model/flatpack_parser/tokens.rb', line 68

def translate str
  return Integer(str)
rescue ArgumentError => err
  return str.to_i
end