class BerkeleyLibrary::Util::ODS::XML::Style::TextProperties
Constants
- COLOR_RE
- FONT_WEIGHT_ATTRS
Attributes
color[R]
country[R]
font_name[R]
font_weight[R]
language[R]
Public Class Methods
new(color: nil, font_name: nil, font_weight: nil, language: 'en', country: 'US', doc:)
click to toggle source
rubocop:disable Metrics/ParameterLists, Style/KeywordParametersOrder
Calls superclass method
BerkeleyLibrary::Util::ODS::XML::ElementNode::new
# File lib/berkeley_library/util/ods/xml/style/text_properties.rb, line 16 def initialize(color: nil, font_name: nil, font_weight: nil, language: 'en', country: 'US', doc:) super(:style, 'text-properties', doc: doc) @color = ensure_color(color) @font_name = font_name @language = language @country = country @font_weight = font_weight set_default_attributes! end
Private Instance Methods
ensure_color(color)
click to toggle source
# File lib/berkeley_library/util/ods/xml/style/text_properties.rb, line 41 def ensure_color(color) return unless color raise ArgumentError, "Not a valid hex color: #{color.inspect}" unless color =~ COLOR_RE color.downcase end
set_default_attributes!()
click to toggle source
rubocop:enable Metrics/ParameterLists, Style/KeywordParametersOrder
# File lib/berkeley_library/util/ods/xml/style/text_properties.rb, line 29 def set_default_attributes! set_attribute('font-name', font_name) if font_name set_attribute(:fo, 'language', language) if language set_attribute(:fo, 'country', country) if country set_attribute(:fo, 'color', color) if color set_font_weight_attributes! end
set_font_weight_attributes!()
click to toggle source
# File lib/berkeley_library/util/ods/xml/style/text_properties.rb, line 37 def set_font_weight_attributes! FONT_WEIGHT_ATTRS.each { |attr| set_attribute(:fo, attr, font_weight) } if font_weight end