Class: RubyFromExcel::ExcelMatrix
- Inherits:
-
ExcelRange
- Object
- ExcelRange
- RubyFromExcel::ExcelMatrix
- Includes:
- Enumerable
- Defined in:
- lib/formulae/run/excel_matrix.rb
Instance Attribute Summary collapse
-
#values ⇒ Object
Returns the value of attribute values.
Instance Method Summary collapse
- #add_columns!(number = 1) ⇒ Object
- #add_rows!(number = 1) ⇒ Object
-
#array_formula_offset(row_index, column_index) ⇒ Object
origin 0,0.
- #columns ⇒ Object
- #each(&block) ⇒ Object
-
#initialize(values) ⇒ ExcelMatrix
constructor
A new instance of ExcelMatrix.
- #rows ⇒ Object
- #to_enum ⇒ Object
- #to_excel_matrix ⇒ Object
Constructor Details
#initialize(values) ⇒ ExcelMatrix
Returns a new instance of ExcelMatrix.
60 61 62 |
# File 'lib/formulae/run/excel_matrix.rb', line 60 def initialize(values) @values = values.is_a?(Array) ? (values.first.is_a?(Array) ? values : [values] ) : [[values]] end |
Instance Attribute Details
#values ⇒ Object
Returns the value of attribute values.
58 59 60 |
# File 'lib/formulae/run/excel_matrix.rb', line 58 def values @values end |
Instance Method Details
#add_columns!(number = 1) ⇒ Object
86 87 88 89 90 91 92 93 |
# File 'lib/formulae/run/excel_matrix.rb', line 86 def add_columns!(number = 1) return if number < 1 number.times do values.each do |row| row << row.last end end end |
#add_rows!(number = 1) ⇒ Object
81 82 83 84 |
# File 'lib/formulae/run/excel_matrix.rb', line 81 def add_rows!(number = 1) return if number < 1 number.times { self.values << self.values.first } end |
#array_formula_offset(row_index, column_index) ⇒ Object
origin 0,0
65 66 67 68 69 |
# File 'lib/formulae/run/excel_matrix.rb', line 65 def array_formula_offset(row_index,column_index) row_index = 0 if values.size == 1 column_index = 0 if values[row_index].size == 1 values[row_index][column_index] || :na end |
#columns ⇒ Object
76 77 78 79 |
# File 'lib/formulae/run/excel_matrix.rb', line 76 def columns return 0 unless values && values.first values.first.size end |
#each(&block) ⇒ Object
95 96 97 |
# File 'lib/formulae/run/excel_matrix.rb', line 95 def each &block block ? to_enum.each { |e| yield e } : to_enum end |
#rows ⇒ Object
71 72 73 74 |
# File 'lib/formulae/run/excel_matrix.rb', line 71 def rows return 0 unless values values.size end |
#to_enum ⇒ Object
99 100 101 102 103 104 105 106 107 |
# File 'lib/formulae/run/excel_matrix.rb', line 99 def to_enum Enumerator.new do |yielder| values.each do |row| row.each do |value| yielder << value end end end end |
#to_excel_matrix ⇒ Object
109 110 111 |
# File 'lib/formulae/run/excel_matrix.rb', line 109 def to_excel_matrix self end |