class Thinreports::Core::Shape::Style::Base

Attributes

accessible_styles[R]

@see .accessible_styles

styles[RW]

@return [Hash]

Public Class Methods

accessible_styles() click to toggle source

@return [Array<Symbol>]

# File lib/thinreports/core/shape/style/base.rb, line 39
def accessible_styles
  @accessible_styles ||= []
end
inherited(s) click to toggle source
# File lib/thinreports/core/shape/style/base.rb, line 43
def inherited(s)
  s.accessible_styles.concat(accessible_styles.dup)
end
new(format, default_styles = {}) click to toggle source

@param [Thinreports::Core::Format::Base] format @param [Hash] default_styles ({})

# File lib/thinreports/core/shape/style/base.rb, line 55
def initialize(format, default_styles = {})
  @format = format
  @styles = default_styles
  @base_styles = format.style || {}

  @accessible_styles = self.class.accessible_styles.dup
end
style_accessible(*style_methods) click to toggle source

@param [Array<Symbol>] style_methods

# File lib/thinreports/core/shape/style/base.rb, line 34
def style_accessible(*style_methods)
  accessible_styles.concat(style_methods)
end
style_accessor(style_method, style) click to toggle source

@param [Symbol] style_method @param [String] style @return [void]

# File lib/thinreports/core/shape/style/base.rb, line 14
def style_accessor(style_method, style)
  style_reader(style_method, style)
  style_writer(style_method, style)
end
style_reader(style_method, style) click to toggle source

@see .style_accessor

# File lib/thinreports/core/shape/style/base.rb, line 20
def style_reader(style_method, style)
  define_method(style_method) do
    read_internal_style(style)
  end
end
style_writer(style_method, style) click to toggle source

@see .style_accessor

# File lib/thinreports/core/shape/style/base.rb, line 27
def style_writer(style_method, style)
  define_method(:"#{style_method}=") do |value|
    write_internal_style(style, value)
  end
end

Public Instance Methods

[](style_method) click to toggle source

@param [Symbol] style_method @return [Object]

# File lib/thinreports/core/shape/style/base.rb, line 65
def [](style_method)
  verify_style_method(style_method)
  send(style_method.to_sym)
end
[]=(style_method, value) click to toggle source

@param [Symbol] style_method @param [String, Number, Array<String, Number>] value

# File lib/thinreports/core/shape/style/base.rb, line 72
def []=(style_method, value)
  verify_style_method(style_method)
  send(:"#{style_method}=", value)
end
copy() click to toggle source

@return [self]

# File lib/thinreports/core/shape/style/base.rb, line 83
def copy
  self.class.new(@format, @styles.empty? ? {} : deep_copy(@styles))
end
finalized_styles() click to toggle source

@return [Hash]

# File lib/thinreports/core/shape/style/base.rb, line 107
def finalized_styles
  @finalized_styles ||=
    if @styles.empty?
      @base_styles.dup
    else
      @base_styles.merge(@styles)
    end
end
has_style?(style_method) click to toggle source

@param [Symbol] style_method @return [Boolean]

# File lib/thinreports/core/shape/style/base.rb, line 102
def has_style?(style_method)
  accessible_styles.include?(style_method)
end
identifier() click to toggle source

@return [String]

# File lib/thinreports/core/shape/style/base.rb, line 78
def identifier
  create_identifier(@styles)
end
read_internal_style(style) click to toggle source

@param [String, Symbol] style @return [Object]

# File lib/thinreports/core/shape/style/base.rb, line 89
def read_internal_style(style)
  style = style.to_s
  @styles.key?(style) ? @styles[style] : @base_styles[style]
end
write_internal_style(style, value) click to toggle source

@param [String, Symbol] style @param [Object] value

# File lib/thinreports/core/shape/style/base.rb, line 96
def write_internal_style(style, value)
  @styles[style.to_s] = value
end

Private Instance Methods

create_identifier(s) click to toggle source

@param [Hash] s @return [String]

# File lib/thinreports/core/shape/style/base.rb, line 120
def create_identifier(s)
  s.empty? ? '' : s.hash.to_s
end
verify_style_method(style_method) click to toggle source

@param [Symbol] style_method @raise Thinreports::Errors::UnknownShapeStyleName

# File lib/thinreports/core/shape/style/base.rb, line 126
def verify_style_method(style_method)
  return if has_style?(style_method)

  raise Thinreports::Errors::UnknownShapeStyleName.new(
    style_method,
    accessible_styles
  )
end
verify_style_value(value, allows, msg = nil) click to toggle source

@param [Object] value @param [Array<Object>] allows @param [String] msg (nil) @raise ArgumentError

# File lib/thinreports/core/shape/style/base.rb, line 139
def verify_style_value(value, allows, msg = nil)
  raise ArgumentError, msg unless allows.include?(value)
end