Class: Condition::Param
- Inherits:
-
Object
- Object
- Condition::Param
- Defined in:
- lib/condition/param.rb
Constant Summary collapse
- @@reader =
nil
Class Method Summary collapse
Instance Method Summary collapse
- #check(name, data) ⇒ Object
- #get(name, index = nil) ⇒ Object
-
#initialize(path, sheet_index = 0, blks: nil, reader: nil) ⇒ Param
constructor
A new instance of Param.
- #item(name) ⇒ Object
- #post(storage) ⇒ Object
- #pre(storage, default = nil) ⇒ Object
- #set_blocks(blocks) ⇒ Object
Constructor Details
#initialize(path, sheet_index = 0, blks: nil, reader: nil) ⇒ Param
Returns a new instance of Param.
17 18 19 20 21 22 23 24 25 |
# File 'lib/condition/param.rb', line 17 def initialize(path, sheet_index=0, blks: nil, reader: nil) if blks.nil? rd = reader.nil? ? Condition::Param.get_reader() : reader blocks = rd.read_sheet(path, sheet_index) set_blocks(blocks) else set_blocks(blks) end end |
Class Method Details
.get_reader ⇒ Object
10 11 12 13 14 15 |
# File 'lib/condition/param.rb', line 10 def self.get_reader() if @@reader.nil? @@reader = Condition::Reader::RooReader.new end @@reader end |
.set_reader(reader) ⇒ Object
6 7 8 |
# File 'lib/condition/param.rb', line 6 def self.set_reader(reader) @@reader = reader end |
Instance Method Details
#check(name, data) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/condition/param.rb', line 51 def check(name, data) item = item(name) raise "#{name} not found in param" if item.nil? item.clear_used_values index = 0 data.each do |line| item.check_line(line, index) index += 1 end raise "#{item.name} not exists row" if item.is_remain_value end |
#get(name, index = nil) ⇒ Object
44 45 46 47 48 49 |
# File 'lib/condition/param.rb', line 44 def get(name, index=nil) item = item(name) return nil if !item return item.values if !index return item.values[index] end |
#item(name) ⇒ Object
40 41 42 |
# File 'lib/condition/param.rb', line 40 def item(name) @item_map[name.to_sym] end |
#post(storage) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/condition/param.rb', line 71 def post(storage) @item_map.each_value do |item| item.clear_used_values list = storage.all(item) index = 0 list.each do |line| item.check_line(line, index) index += 1 end raise "#{item.name} not exists row" if item.is_remain_value end end |
#pre(storage, default = nil) ⇒ Object
63 64 65 66 67 68 69 |
# File 'lib/condition/param.rb', line 63 def pre(storage, default=nil) @item_map.each_value do |item| storage.delete(item) storage.insert(item, default) storage.exec_after(item) end end |
#set_blocks(blocks) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/condition/param.rb', line 27 def set_blocks(blocks) @item_map = {} item_list = [] blocks.each do |rows| item = Condition::ParamItem.new(rows) @item_map[item.name] = item item_list << item end item_list.reverse.each do |it| it.apply_ref(self) end end |