Class: BerkeleyLibrary::Util::ODS::XML::Office::AutomaticStyles
- Inherits:
-
ElementNode
- Object
- ElementNode
- BerkeleyLibrary::Util::ODS::XML::Office::AutomaticStyles
- Defined in:
- lib/berkeley_library/util/ods/xml/office/automatic_styles.rb
Instance Attribute Summary
Attributes inherited from ElementNode
#doc, #element_name, #namespace
Instance Method Summary collapse
-
#add_cell_style(name = nil, protected = false, color = nil, font_weight: nil, wrap: false) ⇒ Object
rubocop:disable Style/OptionalBooleanParameter.
-
#add_child(child) ⇒ Object
------------------------------------------------------------ Public XML::ElementNode overrides.
-
#add_column_style(name = nil, width = nil) ⇒ Object
rubocop:enable Style/OptionalBooleanParameter.
- #add_row_style(name = nil, height = nil) ⇒ Object
- #add_style(style) ⇒ Object
- #add_table_style(name = nil) ⇒ Object
-
#children ⇒ Object
protected
---------------------------------------- Protected XML::ElementNode overrides.
- #create_element ⇒ Object protected
-
#default_style(family) ⇒ Object
------------------------------------------------------------ Accessors.
-
#find_cell_style(protected = false, color: nil, font_weight: nil, wrap: false) ⇒ Object
rubocop:disable Style/OptionalBooleanParameter.
-
#find_column_style(width = nil) ⇒ Object
rubocop:enable Style/OptionalBooleanParameter.
-
#find_or_create_cell_style(protected = false, color: nil, font_weight: nil, wrap: false) ⇒ Object
rubocop:disable Style/OptionalBooleanParameter.
-
#find_or_create_column_style(width = nil) ⇒ Object
rubocop:enable Style/OptionalBooleanParameter.
- #find_or_create_row_style(height = nil) ⇒ Object
- #find_row_style(height = nil) ⇒ Object
-
#initialize(doc:) ⇒ AutomaticStyles
constructor
------------------------------------------------------------ Initializer.
Methods inherited from ElementNode
#attributes, #clear_attribute, #element, #ensure_element!, #prefix, #prefixed_attr_name, #set_attribute
Constructor Details
#initialize(doc:) ⇒ AutomaticStyles
Initializer
17 18 19 |
# File 'lib/berkeley_library/util/ods/xml/office/automatic_styles.rb', line 17 def initialize(doc:) super(:office, 'automatic-styles', doc: doc) end |
Instance Method Details
#add_cell_style(name = nil, protected = false, color = nil, font_weight: nil, wrap: false) ⇒ Object
rubocop:disable Style/OptionalBooleanParameter
37 38 39 40 |
# File 'lib/berkeley_library/util/ods/xml/office/automatic_styles.rb', line 37 def add_cell_style(name = nil, protected = false, color = nil, font_weight: nil, wrap: false) name ||= next_name_for(:table_cell) add_style(Style::CellStyle.new(name, protected, color, font_weight: font_weight, wrap: wrap, styles: self)) end |
#add_child(child) ⇒ Object
Public XML::ElementNode overrides
106 107 108 |
# File 'lib/berkeley_library/util/ods/xml/office/automatic_styles.rb', line 106 def add_child(child) child.is_a?(Style::Style) ? add_style(child) : child.tap { |c| other_children << c } end |
#add_column_style(name = nil, width = nil) ⇒ Object
rubocop:enable Style/OptionalBooleanParameter
43 44 45 46 |
# File 'lib/berkeley_library/util/ods/xml/office/automatic_styles.rb', line 43 def add_column_style(name = nil, width = nil) name ||= next_name_for(:table_column) add_style(Style::ColumnStyle.new(name, width, styles: self)) end |
#add_row_style(name = nil, height = nil) ⇒ Object
48 49 50 51 |
# File 'lib/berkeley_library/util/ods/xml/office/automatic_styles.rb', line 48 def add_row_style(name = nil, height = nil) name ||= next_name_for(:table_row) add_style(Style::RowStyle.new(name, height, styles: self)) end |
#add_style(style) ⇒ Object
58 59 60 61 62 |
# File 'lib/berkeley_library/util/ods/xml/office/automatic_styles.rb', line 58 def add_style(style) raise ArgumentError, "Not a style: #{style.inspect}" unless style.is_a?(Style::Style) style.tap { |s| add_or_insert_style(s) } end |
#add_table_style(name = nil) ⇒ Object
53 54 55 56 |
# File 'lib/berkeley_library/util/ods/xml/office/automatic_styles.rb', line 53 def add_table_style(name = nil) name ||= next_name_for(:table) add_style(Style::TableStyle.new(name, styles: self)) end |
#children ⇒ Object (protected)
Protected XML::ElementNode overrides
118 119 120 |
# File 'lib/berkeley_library/util/ods/xml/office/automatic_styles.rb', line 118 def children [other_children, Style::Family.map { |f| styles_for_family(f) }].flatten end |
#create_element ⇒ Object (protected)
122 123 124 125 126 |
# File 'lib/berkeley_library/util/ods/xml/office/automatic_styles.rb', line 122 def create_element Style::Family.each { |f| default_style(f) } super end |
#default_style(family) ⇒ Object
Accessors
24 25 26 27 28 29 |
# File 'lib/berkeley_library/util/ods/xml/office/automatic_styles.rb', line 24 def default_style(family) first_style = styles_for_family(family).first return first_style if first_style add_default_style(family) end |
#find_cell_style(protected = false, color: nil, font_weight: nil, wrap: false) ⇒ Object
rubocop:disable Style/OptionalBooleanParameter
65 66 67 |
# File 'lib/berkeley_library/util/ods/xml/office/automatic_styles.rb', line 65 def find_cell_style(protected = false, color: nil, font_weight: nil, wrap: false) styles_for_family(:table_cell).find { |s| [s.protected?, s.color, s.font_weight, s.wrap?] == [protected, color, font_weight, wrap] } end |
#find_column_style(width = nil) ⇒ Object
rubocop:enable Style/OptionalBooleanParameter
70 71 72 73 |
# File 'lib/berkeley_library/util/ods/xml/office/automatic_styles.rb', line 70 def find_column_style(width = nil) w = width || Style::ColumnStyle::DEFAULT_WIDTH styles_for_family(:table_column).find { |s| s.width == w } end |
#find_or_create_cell_style(protected = false, color: nil, font_weight: nil, wrap: false) ⇒ Object
rubocop:disable Style/OptionalBooleanParameter
81 82 83 84 85 86 |
# File 'lib/berkeley_library/util/ods/xml/office/automatic_styles.rb', line 81 def find_or_create_cell_style(protected = false, color: nil, font_weight: nil, wrap: false) existing_style = find_cell_style(protected, color: color, font_weight: font_weight, wrap: wrap) return existing_style if existing_style add_cell_style(nil, protected, color, font_weight: font_weight, wrap: wrap) end |
#find_or_create_column_style(width = nil) ⇒ Object
rubocop:enable Style/OptionalBooleanParameter
89 90 91 92 93 94 |
# File 'lib/berkeley_library/util/ods/xml/office/automatic_styles.rb', line 89 def find_or_create_column_style(width = nil) existing_style = find_column_style(width) return existing_style if existing_style add_column_style(nil, width) end |
#find_or_create_row_style(height = nil) ⇒ Object
96 97 98 99 100 101 |
# File 'lib/berkeley_library/util/ods/xml/office/automatic_styles.rb', line 96 def find_or_create_row_style(height = nil) existing_style = find_row_style(height) return existing_style if existing_style add_row_style(nil, height) end |
#find_row_style(height = nil) ⇒ Object
75 76 77 78 |
# File 'lib/berkeley_library/util/ods/xml/office/automatic_styles.rb', line 75 def find_row_style(height = nil) h = height || Style::RowStyle::DEFAULT_HEIGHT styles_for_family(:table_row).find { |s| s.height == h } end |