Class: Wukong::FlatPack::Tokens::BoolToken

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

Constant Summary collapse

TRUE_TOKENS =
['t','y','1']
FALSE_TOKENS =
['f','n','0']

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

TODO: Add back multi-char options and think through allowing padding TODO: Allow users to override true and false



104
105
106
107
# File 'lib/wukong/model/flatpack_parser/tokens.rb', line 104

def re
  return "(?:#{(TRUE_TOKENS + TRUE_TOKENS.map {|c| c.upcase} +
               FALSE_TOKENS + FALSE_TOKENS.map{|c| c.upcase}).join('|')})"
end

#translate(str) ⇒ Object



109
110
111
112
113
114
115
116
117
# File 'lib/wukong/model/flatpack_parser/tokens.rb', line 109

def translate str
  if TRUE_TOKENS.include?(str.downcase)
    return true
  elsif FALSE_TOKENS.include?(str.downcase)
    return false
  else
    return nil
  end
end