Class: RubyFromExcel::Cell
- Inherits:
-
Object
- Object
- RubyFromExcel::Cell
- Defined in:
- lib/cells/cell.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#dependencies ⇒ Object
Returns the value of attribute dependencies.
-
#reference ⇒ Object
Returns the value of attribute reference.
-
#worksheet ⇒ Object
Returns the value of attribute worksheet.
-
#xml_type ⇒ Object
Returns the value of attribute xml_type.
-
#xml_value ⇒ Object
Returns the value of attribute xml_value.
Instance Method Summary collapse
- #alter_other_cells_if_required ⇒ Object
- #can_be_replaced_with_value? ⇒ Boolean
- #debug ⇒ Object
-
#initialize(worksheet, xml = nil) ⇒ Cell
constructor
A new instance of Cell.
- #inspect ⇒ Object
- #parse_xml(xml) ⇒ Object
- #test ⇒ Object
- #to_ruby(r = RubyScriptWriter.new) ⇒ Object
- #to_s ⇒ Object
- #to_test(r = RubySpecWriter.new) ⇒ Object
- #tolerance_for(value, tolerance = 0.1, maximum = 1e-8) ⇒ Object
- #value ⇒ Object
- #value_for_including ⇒ Object
- #work_out_dependencies ⇒ Object
Constructor Details
#initialize(worksheet, xml = nil) ⇒ Cell
Returns a new instance of Cell.
6 7 8 9 10 |
# File 'lib/cells/cell.rb', line 6 def initialize(worksheet,xml = nil) self.worksheet = worksheet parse_xml xml debug end |
Instance Attribute Details
#dependencies ⇒ Object
Returns the value of attribute dependencies.
4 5 6 |
# File 'lib/cells/cell.rb', line 4 def dependencies @dependencies end |
#reference ⇒ Object
Returns the value of attribute reference.
4 5 6 |
# File 'lib/cells/cell.rb', line 4 def reference @reference end |
#worksheet ⇒ Object
Returns the value of attribute worksheet.
4 5 6 |
# File 'lib/cells/cell.rb', line 4 def worksheet @worksheet end |
#xml_type ⇒ Object
Returns the value of attribute xml_type.
4 5 6 |
# File 'lib/cells/cell.rb', line 4 def xml_type @xml_type end |
#xml_value ⇒ Object
Returns the value of attribute xml_value.
4 5 6 |
# File 'lib/cells/cell.rb', line 4 def xml_value @xml_value end |
Instance Method Details
#alter_other_cells_if_required ⇒ Object
19 20 21 |
# File 'lib/cells/cell.rb', line 19 def alter_other_cells_if_required # nil end |
#can_be_replaced_with_value? ⇒ Boolean
50 51 52 |
# File 'lib/cells/cell.rb', line 50 def can_be_replaced_with_value? false end |
#debug ⇒ Object
98 99 100 |
# File 'lib/cells/cell.rb', line 98 def debug RubyFromExcel.debug(:cells,"#{worksheet.name}.#{reference} -> #{} -> #{xml_value} (#{xml_type})") end |
#inspect ⇒ Object
94 95 96 |
# File 'lib/cells/cell.rb', line 94 def inspect "(cell: #{to_s} with formula:#{respond_to?(:ast) ? ast.inspect : "na"} and value '#{value}' of type '#{xml_type}')" end |
#parse_xml(xml) ⇒ Object
12 13 14 15 16 17 |
# File 'lib/cells/cell.rb', line 12 def parse_xml(xml) return nil unless xml self.reference = Reference.new(xml['r'],worksheet) self.xml_value = xml.at_css("v").content self.xml_type = xml['t'] end |
#test ⇒ Object
39 40 41 42 |
# File 'lib/cells/cell.rb', line 39 def test return "== #{value}" if xml_type "be_within(#{tolerance_for(value.to_f)}).of(#{value.to_f})" end |
#to_ruby(r = RubyScriptWriter.new) ⇒ Object
27 28 29 30 |
# File 'lib/cells/cell.rb', line 27 def to_ruby(r = RubyScriptWriter.new) r.put_simple_method reference.to_ruby, ruby_value r.to_s end |
#to_s ⇒ Object
90 91 92 |
# File 'lib/cells/cell.rb', line 90 def to_s "#{worksheet}.#{reference}" end |
#to_test(r = RubySpecWriter.new) ⇒ Object
32 33 34 35 36 37 |
# File 'lib/cells/cell.rb', line 32 def to_test(r = RubySpecWriter.new) r.put_spec "cell #{reference.to_ruby} should equal #{value}" do r.puts "#{worksheet}.#{reference.to_ruby}.should #{test}" end r.to_s end |
#tolerance_for(value, tolerance = 0.1, maximum = 1e-8) ⇒ Object
44 45 46 47 48 |
# File 'lib/cells/cell.rb', line 44 def tolerance_for(value,tolerance = 0.1, maximum = 1e-8) tolerance = value.abs * tolerance tolerance = maximum if tolerance < maximum tolerance end |
#value ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/cells/cell.rb', line 54 def value value = xml_value case xml_type when 'str' return value.inspect when 's' return SharedStrings.shared_string_for(value.to_i).inspect when 'e' return ":#{value.gsub(/[^a-zA-Z]/,'').downcase}" when 'b' return 'true' if value == '1' return 'false' if value == '0' return Formula.parse(value).visit(FormulaBuilder.new) else return Formula.parse(value).visit(FormulaBuilder.new) end end |
#value_for_including ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/cells/cell.rb', line 72 def value_for_including value = xml_value case xml_type when 'str' return value when 's' return SharedStrings.shared_string_for(value.to_i) when 'e' return ":#{value.gsub(/[^a-zA-Z]/,'').downcase}" when 'b' return 'true' if value == '1' return 'false' if value == '0' return Formula.parse(value).visit(FormulaBuilder.new) else return Formula.parse(value).visit(FormulaBuilder.new) end end |
#work_out_dependencies ⇒ Object
23 24 25 |
# File 'lib/cells/cell.rb', line 23 def work_out_dependencies self.dependencies = [] end |