Class: LS4::WeightInfo

Inherits:
Object
  • Object
show all
Defined in:
lib/ls4/logic/weight.rb

Constant Summary collapse

DEFAULT_WEIGHT =
10

Instance Method Summary collapse

Constructor Details

#initializeWeightInfo

Returns a new instance of WeightInfo.



24
25
26
27
# File 'lib/ls4/logic/weight.rb', line 24

def initialize
	@map = {}  # {rsid => weight}
	update_hash
end

Instance Method Details

#closeObject



34
35
# File 'lib/ls4/logic/weight.rb', line 34

def close
end

#from_msgpack(obj) ⇒ Object



93
94
95
96
97
# File 'lib/ls4/logic/weight.rb', line 93

def from_msgpack(obj)
	@map = obj
	on_change
	self
end

#get_all_with_default(rsids) ⇒ Object



77
78
79
80
81
82
83
# File 'lib/ls4/logic/weight.rb', line 77

def get_all_with_default(rsids)
	result = {}
	rsids.each {|rsid|
		result[rsid] = @map[rsid] || DEFAULT_WEIGHT
	}
	result
end

#get_hashObject



85
86
87
# File 'lib/ls4/logic/weight.rb', line 85

def get_hash
	@hash
end

#get_registered_rsidsObject



69
70
71
# File 'lib/ls4/logic/weight.rb', line 69

def get_registered_rsids
	@map.keys
end

#get_registered_weightsObject



73
74
75
# File 'lib/ls4/logic/weight.rb', line 73

def get_registered_weights
	@map.dup
end

#get_weight(rsid) ⇒ Object



65
66
67
# File 'lib/ls4/logic/weight.rb', line 65

def get_weight(rsid)
	@map[rsid] || DEFAULT_WEIGHT
end

#open(path) ⇒ Object



29
30
31
32
# File 'lib/ls4/logic/weight.rb', line 29

def open(path)
	@path = path
	read
end

#reset_weight(rsid) ⇒ Object



46
47
48
49
50
51
52
# File 'lib/ls4/logic/weight.rb', line 46

def reset_weight(rsid)
	unless @map.delete(rsid)
		return nil
	end
	on_change
	true
end

#set_defaults(rsids) ⇒ Object



54
55
56
57
58
59
60
61
62
63
# File 'lib/ls4/logic/weight.rb', line 54

def set_defaults(rsids)
	#@map.reject! {|rsid,weight|
	#	!rsids.include?(rsid)
	#}
	rsids.each {|rsid|
		@map[rsid] ||= DEFAULT_WEIGHT
	}
	on_change
	true
end

#set_weight(rsid, weight) ⇒ Object



37
38
39
40
41
42
43
44
# File 'lib/ls4/logic/weight.rb', line 37

def set_weight(rsid, weight)
	if @map[rsid] == weight
		return nil
	end
	@map[rsid] = weight
	on_change
	true
end

#to_msgpack(out = '') ⇒ Object



89
90
91
# File 'lib/ls4/logic/weight.rb', line 89

def to_msgpack(out = '')
	@map.to_msgpack(out)
end