Class: Writexlsx::Package::Comment
- Inherits:
-
Object
- Object
- Writexlsx::Package::Comment
- Includes:
- Utility
- Defined in:
- lib/write_xlsx/package/comments.rb
Constant Summary collapse
- DEFAULT_COLOR =
what color ?
81
- DEFAULT_WIDTH =
128
- DEFAULT_HEIGHT =
74
Constants included from Utility
Utility::COL_MAX, Utility::ROW_MAX, Utility::SHEETNAME_MAX, Utility::STR_MAX
Instance Attribute Summary collapse
-
#author ⇒ Object
Returns the value of attribute author.
-
#col ⇒ Object
readonly
Returns the value of attribute col.
-
#color ⇒ Object
readonly
Returns the value of attribute color.
-
#row ⇒ Object
readonly
Returns the value of attribute row.
-
#string ⇒ Object
readonly
Returns the value of attribute string.
-
#vertices ⇒ Object
readonly
Returns the value of attribute vertices.
-
#visible ⇒ Object
Returns the value of attribute visible.
Instance Method Summary collapse
- #backgrount_color(color) ⇒ Object
- #default_start_col(col) ⇒ Object
- #default_start_row(row) ⇒ Object
- #default_x_offset(col) ⇒ Object
- #default_y_offset(row) ⇒ Object
-
#initialize(workbook, worksheet, row, col, string, options = {}) ⇒ Comment
constructor
A new instance of Comment.
-
#rgb_color(rgb) ⇒ Object
Minor modification to allow comparison testing.
Methods included from Utility
#absolute_char, delete_files, #put_deprecate_message, #substitute_cellref, #underline_attributes, #xl_cell_to_rowcol, #xl_col_to_name, #xl_range, #xl_range_formula, #xl_rowcol_to_cell, #xml_str
Constructor Details
#initialize(workbook, worksheet, row, col, string, options = {}) ⇒ Comment
Returns a new instance of Comment.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/write_xlsx/package/comments.rb', line 20 def initialize(workbook, worksheet, row, col, string, = {}) ||= {} @workbook = workbook @worksheet = worksheet @row = row @col = col @string = string[0, STR_MAX] @author = [:author] @color = backgrount_color([:color] || DEFAULT_COLOR) @start_cell = [:start_cell] @start_row, @start_col = if @start_cell substitute_cellref(@start_cell) else [ [:start_row], [:start_col] ] end @start_row ||= default_start_row(row) @start_col ||= default_start_col(col) @visible = [:visible] @x_offset = [:x_offset] || default_x_offset(col) @y_offset = [:y_offset] || default_y_offset(row) @x_scale = [:x_scale] || 1 @y_scale = [:y_scale] || 1 @width = (0.5 + ([:width] || DEFAULT_WIDTH) * @x_scale).to_i @height = (0.5 + ([:height] || DEFAULT_HEIGHT) * @y_scale).to_i @vertices = @worksheet.position_object_pixels( @start_col, @start_row, @x_offset, @y_offset, @width, @height ) << [@width, @height] end |
Instance Attribute Details
#author ⇒ Object
Returns the value of attribute author.
18 19 20 |
# File 'lib/write_xlsx/package/comments.rb', line 18 def @author end |
#col ⇒ Object (readonly)
Returns the value of attribute col.
17 18 19 |
# File 'lib/write_xlsx/package/comments.rb', line 17 def col @col end |
#color ⇒ Object (readonly)
Returns the value of attribute color.
17 18 19 |
# File 'lib/write_xlsx/package/comments.rb', line 17 def color @color end |
#row ⇒ Object (readonly)
Returns the value of attribute row.
17 18 19 |
# File 'lib/write_xlsx/package/comments.rb', line 17 def row @row end |
#string ⇒ Object (readonly)
Returns the value of attribute string.
17 18 19 |
# File 'lib/write_xlsx/package/comments.rb', line 17 def string @string end |
#vertices ⇒ Object (readonly)
Returns the value of attribute vertices.
17 18 19 |
# File 'lib/write_xlsx/package/comments.rb', line 17 def vertices @vertices end |
#visible ⇒ Object
Returns the value of attribute visible.
18 19 20 |
# File 'lib/write_xlsx/package/comments.rb', line 18 def visible @visible end |
Instance Method Details
#backgrount_color(color) ⇒ Object
50 51 52 53 54 55 56 57 58 59 |
# File 'lib/write_xlsx/package/comments.rb', line 50 def backgrount_color(color) color_id = Format.get_color(color) if color_id == 0 @color = '#ffffe1' else rgb = @workbook.palette[color_id - 8] @color = "##{rgb_color(rgb)} [#{color_id}]\n" end end |
#default_start_col(col) ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/write_xlsx/package/comments.rb', line 86 def default_start_col(col) case col when COL_MAX - 3 COL_MAX - 6 when COL_MAX - 2 COL_MAX - 5 when COL_MAX - 1 COL_MAX - 4 else col + 1 end end |
#default_start_row(row) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/write_xlsx/package/comments.rb', line 71 def default_start_row(row) case row when 0 0 when ROW_MAX - 3 ROW_MAX - 7 when ROW_MAX - 2 ROW_MAX - 6 when ROW_MAX - 1 ROW_MAX - 5 else row - 1 end end |
#default_x_offset(col) ⇒ Object
99 100 101 102 103 104 105 106 |
# File 'lib/write_xlsx/package/comments.rb', line 99 def default_x_offset(col) case col when COL_MAX - 3, COL_MAX - 2, COL_MAX - 1 49 else 15 end end |
#default_y_offset(row) ⇒ Object
108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/write_xlsx/package/comments.rb', line 108 def default_y_offset(row) case row when 0 2 when ROW_MAX - 3, ROW_MAX - 2 16 when ROW_MAX - 1 14 else 10 end end |
#rgb_color(rgb) ⇒ Object
Minor modification to allow comparison testing. Change RGB colors from long format, ffcc00 to short format fc0 used by VML.
63 64 65 66 67 68 69 |
# File 'lib/write_xlsx/package/comments.rb', line 63 def rgb_color(rgb) result = sprintf("%02x%02x%02x", *rgb) if result =~ /^([0-9a-f])\1([0-9a-f])\2([0-9a-f])\3$/ result = "#{$1}#{$2}#{$3}" end result end |