Module: Extract::Tree::Range

Defined in:
lib/extract/tree/range.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.cells_in_range(str) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/extract/tree/range.rb', line 18

def cells_in_range(str)
  arr = str.split(":").tap { |x| raise "bad" unless x.size == 2 }.map do |c|
    raise "bad" unless c =~ /^([A-Z])([0-9]+)$/
    OpenStruct.new(:row => $2, :col => $1)
  end
  cells_in_range_nodes(*arr)
end

.cells_in_range_nodes(a, b) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/extract/tree/range.rb', line 6

def cells_in_range_nodes(a,b)
  res = []
  ((a.row)..(b.row)).each do |r|
    tmp = []
    ((a.col)..(b.col)).each do |c|
      tmp << "#{c}#{r}"
    end
    res << tmp
  end
  res
end

Instance Method Details

#depsObject



46
47
48
49
50
51
52
53
54
55
# File 'lib/extract/tree/range.rb', line 46

def deps
  res = []
  ((a.row)..(b.row)).each do |r|
    tmp = []
    ((a.col)..(b.col)).each do |c|
      res << "#{c}#{r}"
    end
  end
  res.flatten.select { |x| x }
end

#excel_valueObject



39
40
41
42
43
44
45
# File 'lib/extract/tree/range.rb', line 39

def excel_value
  Extract::Tree::Range.cells_in_range_nodes(a,b).map do |arr|
    arr.map do |c|
      find_sheet[c]
    end
  end
end

#excel_value_oldObject



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/extract/tree/range.rb', line 27

def excel_value_old
  res = []
  ((a.row)..(b.row)).each do |r|
    tmp = []
    ((a.col)..(b.col)).each do |c|
      tmp << find_sheet["#{c}#{r}"]
    end
    res << tmp
  end
  res
end