Class: Pulo::FrameCell
- Inherits:
-
Object
- Object
- Pulo::FrameCell
- Defined in:
- lib/pulo/frames/frame_cell.rb
Instance Method Summary collapse
- #column ⇒ Object
- #empty? ⇒ Boolean
- #error? ⇒ Boolean
-
#initialize(parent_column, parent_row, value = nil) ⇒ FrameCell
constructor
A new instance of FrameCell.
- #row ⇒ Object
- #set_error ⇒ Object
- #to_s ⇒ Object
- #unset_error ⇒ Object
- #value ⇒ Object
- #value=(val) ⇒ Object
- #value_column? ⇒ Boolean
Constructor Details
#initialize(parent_column, parent_row, value = nil) ⇒ FrameCell
Returns a new instance of FrameCell.
4 5 6 7 8 9 |
# File 'lib/pulo/frames/frame_cell.rb', line 4 def initialize(parent_column,parent_row,value=nil) @parent_column=parent_column @parent_row=parent_row @error=false self.value=value end |
Instance Method Details
#column ⇒ Object
11 12 13 |
# File 'lib/pulo/frames/frame_cell.rb', line 11 def column @parent_column end |
#empty? ⇒ Boolean
19 20 21 |
# File 'lib/pulo/frames/frame_cell.rb', line 19 def empty? @value.nil? end |
#error? ⇒ Boolean
33 34 35 |
# File 'lib/pulo/frames/frame_cell.rb', line 33 def error? @error end |
#row ⇒ Object
15 16 17 |
# File 'lib/pulo/frames/frame_cell.rb', line 15 def row @parent_row end |
#set_error ⇒ Object
27 28 29 |
# File 'lib/pulo/frames/frame_cell.rb', line 27 def set_error @error=true end |
#to_s ⇒ Object
74 75 76 77 78 79 80 |
# File 'lib/pulo/frames/frame_cell.rb', line 74 def to_s begin @parent_column.formatter.call(value).ljust(@parent_column.width,' ') rescue Exception => e value.to_s end end |
#unset_error ⇒ Object
30 31 32 |
# File 'lib/pulo/frames/frame_cell.rb', line 30 def unset_error @error=false end |
#value ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/pulo/frames/frame_cell.rb', line 37 def value #raise "Column (#{@parent_column.name}) requires re-calc, value not available." if @parent_column.recalc_required return "ERR" if error? #return "UNK" if @parent_column.recalc_required #return "NIL" if empty? @value end |
#value=(val) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/pulo/frames/frame_cell.rb', line 45 def value=(val) if @parent_column.column_class==NilClass @parent_column.column_class=val.class if val.class.respond_to?(:quantity_name) @parent_column.column_unit=val.unit end end if val.class.respond_to?(:quantity_name) if val.unit.name!=@parent_column.column_unit.name val=val.send(@parent_column.column_unit.name) end end if @parent_column.column_class!=NilClass && val.class!=NilClass if val.class.respond_to?(:quantity_name) unless val.class.dimensions==@parent_column.column_class.dimensions raise "Tried to set a value (#{val.to_s}) of class #{val.class} with dimensions #{val.class.dimensions} on column #{@parent_column.name} which already has a defined class of #{@parent_column.column_class}." end else unless val.class==@parent_column.column_class raise "Tried to set a value (#{val.to_s}) of class #{val.class} on column #{@parent_column.name} which already has a defined class of #{@parent_column.column_class}." end end end @value=val end |
#value_column? ⇒ Boolean
23 24 25 |
# File 'lib/pulo/frames/frame_cell.rb', line 23 def value_column? @parent_column.value_column? end |