class Fsinv::LookupTable
Attributes
idcursor[RW]
val_map[RW]
Public Class Methods
new()
click to toggle source
# File lib/fsinv/lookuptable.rb, line 7 def initialize @val_map = Hash.new @idcursor = 0 end
Public Instance Methods
add(value)
click to toggle source
# File lib/fsinv/lookuptable.rb, line 16 def add(value) if self.contains?(value) return get_id(value) elsif value == "" || value == nil return nil else @idcursor += 1 @val_map[@idcursor] = value return @idcursor end end
as_json(options = { })
click to toggle source
# File lib/fsinv/lookuptable.rb, line 55 def as_json(options = { }) return to_a end
contains?(value)
click to toggle source
# File lib/fsinv/lookuptable.rb, line 12 def contains?(value) return value == "" ? false : @val_map.has_value?(value) end
empty?()
click to toggle source
# File lib/fsinv/lookuptable.rb, line 29 def empty? return @val_map.empty? end
from_json(json)
click to toggle source
# File lib/fsinv/lookuptable.rb, line 49 def from_json(json) json.each do |entry| self.add(entry["value"]) unless self.contains?(entry["value"]) end end
get_id(value)
click to toggle source
# File lib/fsinv/lookuptable.rb, line 33 def get_id(value) return self.contains?(value) ? @val_map.key(value) : nil end
get_value(id)
click to toggle source
# File lib/fsinv/lookuptable.rb, line 37 def get_value(id) return self.contains?(value) ? @val_map[id] : nil end
marshal_dump()
click to toggle source
# File lib/fsinv/lookuptable.rb, line 63 def marshal_dump return { 'val_map' => val_map, 'idcursor' => idcursor } end
marshal_load(data)
click to toggle source
# File lib/fsinv/lookuptable.rb, line 70 def marshal_load(data) self.val_map = data['val_map'] self.idcursor = data['idcursor'] end
to_a()
click to toggle source
# File lib/fsinv/lookuptable.rb, line 41 def to_a table_arr = [] @val_map.each do | id, val | table_arr << {"id" => id, "value" => val} end return table_arr end
to_json(*a)
click to toggle source
# File lib/fsinv/lookuptable.rb, line 59 def to_json(*a) return as_json.to_json(*a) end