Class: DrawioDsl::Schema::StyleBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/drawio_dsl/schema/style_builder.rb

Overview

Build the style attribute for shape elements

Requirements:

Need to be able to take a string and break it up into style parts
A style part is usually a lowerCamel equals value pair (e.g. fontSize=12)
but sometimes it is just a singular value, (e.g. ellipse)
A string may also contain more then one style part separated by semi-colons
e.g. overflow=fill;fontSize=12;fontFamily=Helvetica

The purpose of this class is to build a style attribute with unique values and
to take inputs from either single key/value pairs or string following the
pattern previously described.

Instance Method Summary collapse

Constructor Details

#initializeStyleBuilder

Returns a new instance of StyleBuilder.



18
19
20
# File 'lib/drawio_dsl/schema/style_builder.rb', line 18

def initialize
  @style_parts = []
end

Instance Method Details

#add(value) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/drawio_dsl/schema/style_builder.rb', line 22

def add(value)
  return if value.nil?

  if value.is_a?(Symbol)
    set(value)
    return
  end

  value.split(';') do |v|
    kv = v.to_s.split('=')

    if kv.length == 1
      set(v.to_s)
    else
      set_kv(kv[0], kv[1])
    end
  end
end

#add_kv(key, value) ⇒ Object



41
42
43
44
45
# File 'lib/drawio_dsl/schema/style_builder.rb', line 41

def add_kv(key, value)
  key = camel_case_lower(key) if key.is_a?(Symbol)

  set_kv(key, value)
end

#styleObject



47
48
49
# File 'lib/drawio_dsl/schema/style_builder.rb', line 47

def style
  @style_parts.join(';')
end