Class: Axlsx::ProtectedRanges
- Inherits:
-
SimpleTypedList
- Object
- Array
- SimpleTypedList
- Axlsx::ProtectedRanges
- Defined in:
- lib/axlsx/workbook/worksheet/protected_ranges.rb
Overview
A self serializing collection of ranges that should be protected in the worksheet
Instance Attribute Summary collapse
-
#worksheet ⇒ Object
readonly
Returns the value of attribute worksheet.
Instance Method Summary collapse
-
#add_range(cells) ⇒ Object
Adds a protected range.
-
#initialize(worksheet) ⇒ ProtectedRanges
constructor
A new instance of ProtectedRanges.
-
#to_xml_string(str = +'')) ⇒ String
Serializes the protected ranges.
Constructor Details
#initialize(worksheet) ⇒ ProtectedRanges
Returns a new instance of ProtectedRanges.
9 10 11 12 13 14 |
# File 'lib/axlsx/workbook/worksheet/protected_ranges.rb', line 9 def initialize(worksheet) raise ArgumentError, 'You must provide a worksheet' unless worksheet.is_a?(Worksheet) super(ProtectedRange) @worksheet = worksheet end |
Instance Attribute Details
#worksheet ⇒ Object (readonly)
Returns the value of attribute worksheet.
7 8 9 |
# File 'lib/axlsx/workbook/worksheet/protected_ranges.rb', line 7 def worksheet @worksheet end |
Instance Method Details
#add_range(cells) ⇒ Object
Adds a protected range
18 19 20 21 22 23 24 25 26 |
# File 'lib/axlsx/workbook/worksheet/protected_ranges.rb', line 18 def add_range(cells) sqref = if cells.is_a?(String) cells elsif cells.is_a?(SimpleTypedList) || cells.is_a?(Array) Axlsx.cell_range(cells, false) end self << ProtectedRange.new(sqref: sqref, name: "Range#{size}") last end |
#to_xml_string(str = +'')) ⇒ String
Serializes the protected ranges
31 32 33 34 35 36 37 |
# File 'lib/axlsx/workbook/worksheet/protected_ranges.rb', line 31 def to_xml_string(str = +'') return if empty? str << '<protectedRanges>' each { |range| range.to_xml_string(str) } str << '</protectedRanges>' end |