class FixSymbol::Base

Attributes

id[RW]

Both id and token can be accessed as method.

token[RW]

Both id and token can be accessed as method.

Public Class Methods

new(value=nil) click to toggle source

@!method initialize

Initializing, which is usually executed by AnvylToken (insted of being called directly)
allows the token/id to be set and searches for the correspondig pair.
If no value is set, the Token will just be empty.

@param value [Fixnum] Token's id.
@param value [Symbol] Token's token (symbol).
@param value [String] Token's token (symbol) which is converted to symbol.
# File lib/fix_symbol/base.rb, line 43
def initialize(value=nil)
        if value
                if value.is_a? Fixnum
                        self.id=value
                elsif value.is_a? Symbol
                        self.token = value
                elsif value.is_a? String
                        self.token = value.to_sym
                end
        end
end

Public Instance Methods

find_by_id(id) click to toggle source

@!method find_by_id Searches for the correspoding token for a given id. @return [Fixnum] found id @return [NilClass] nil when token is not found

@note YAML:

Make sure file exists, load with YAML and fetch in array.
# File lib/fix_symbol/base.rb, line 101
def find_by_id(id)
        if @@use == :yml
                if File.exists? @@file
                        data = YAML.load_file(@@file)
                        begin
                                token = data[id].to_sym unless data == nil
                        rescue
                                token = :notfound
                                puts "Token #{id} not found."
                        end
                else
                        raise 'No file found.'
                end
        end
        return token
end
find_by_token(token) click to toggle source

@!method find_by_token Searches for the correspoding id for a given token. @return [Fixnum] found id @return [NilClass] nil when token is not found

@note YAML:

Make sure file exists, load with YAML and use index in array.
# File lib/fix_symbol/base.rb, line 127
def find_by_token(token)
        if @@use == :yml
                if File.exists? @@file
                        data = YAML.load_file(@@file)
                        id = data.index token.to_s unless data == nil
                else
                        raise 'No file found.'
                end
        end
        return id
end
id=(id) click to toggle source

@!method id

Sets Token's id and searches corresponding symbol.
# File lib/fix_symbol/base.rb, line 59
def id=(id)
        @id = id
        @token = find_by_id(id)
end
token=(token) click to toggle source

@!method token

Sets Token's token and searches corresponding id.
# File lib/fix_symbol/base.rb, line 68
def token=(token)
        @token = token
        @id = find_by_token(token)
end