Class: Archimate::Svg::Connection
- Inherits:
-
Object
- Object
- Archimate::Svg::Connection
- Defined in:
- lib/archimate/svg/connection.rb
Instance Attribute Summary collapse
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
-
#css_style ⇒ Object
readonly
Returns the value of attribute css_style.
Instance Method Summary collapse
-
#css_classify(str) ⇒ Object
TODO: StringRefinements refinement isn’t working in this class, so added this method here.
- #id ⇒ Object
-
#initialize(connection) ⇒ Connection
constructor
A new instance of Connection.
- #line_style ⇒ Object
- #path_attrs ⇒ Object
-
#path_class ⇒ Object
Look at the type (if any of the path and set the class appropriately).
- #render(svg) ⇒ Object
- #text_position ⇒ Object
- #to_svg(xml) ⇒ Object
Constructor Details
#initialize(connection) ⇒ Connection
Returns a new instance of Connection.
9 10 11 12 13 |
# File 'lib/archimate/svg/connection.rb', line 9 def initialize(connection) @connection = connection @path = Path.new(@connection) @css_style = CssStyle.new(connection.style) end |
Instance Attribute Details
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
6 7 8 |
# File 'lib/archimate/svg/connection.rb', line 6 def connection @connection end |
#css_style ⇒ Object (readonly)
Returns the value of attribute css_style.
7 8 9 |
# File 'lib/archimate/svg/connection.rb', line 7 def css_style @css_style end |
Instance Method Details
#css_classify(str) ⇒ Object
TODO: StringRefinements refinement isn’t working in this class, so added this method here. Investigate.
86 87 88 89 90 91 |
# File 'lib/archimate/svg/connection.rb', line 86 def css_classify(str) str.gsub(/::/, '/') .gsub(/([A-Z]+)([A-Z][a-z])/, '\1-\2') .gsub(/([a-z\d])([A-Z])/, '\1-\2') .downcase end |
#id ⇒ Object
73 74 75 |
# File 'lib/archimate/svg/connection.rb', line 73 def id connection.relationship&.id || connection.id end |
#line_style ⇒ Object
42 43 44 45 46 47 48 49 50 51 |
# File 'lib/archimate/svg/connection.rb', line 42 def line_style style = connection.style return "" if style.nil? { "stroke": style.line_color&.to_rgba, "stroke-width": style.line_width }.delete_if { |_key, value| value.nil? } .map { |key, value| "#{key}:#{value};" } .join("") end |
#path_attrs ⇒ Object
64 65 66 67 68 69 70 71 |
# File 'lib/archimate/svg/connection.rb', line 64 def path_attrs { id: id, class: path_class, d: @path.d, style: line_style } end |
#path_class ⇒ Object
Look at the type (if any of the path and set the class appropriately)
78 79 80 81 82 83 |
# File 'lib/archimate/svg/connection.rb', line 78 def path_class [ "archimate", css_classify(connection&.relationship&.type || "default") ].join("-") + " archimate-relationship" end |
#render(svg) ⇒ Object
15 16 17 18 19 20 |
# File 'lib/archimate/svg/connection.rb', line 15 def render(svg) Nokogiri::XML::Builder.with(svg) do |xml| to_svg(xml) end svg end |
#text_position ⇒ Object
53 54 55 56 57 58 59 60 61 62 |
# File 'lib/archimate/svg/connection.rb', line 53 def text_position case connection.style when 0 0.1 # "10%" when 1 0.9 # "90%" else 0.5 # "50%" end end |
#to_svg(xml) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/archimate/svg/connection.rb', line 22 def to_svg(xml) return if connection.source.nodes.include?(connection.target) xml.path(path_attrs) do xml.title @connection.description end name = connection&.relationship&.name&.strip return if name.nil? || name.empty? pt = @path.point(text_position) xml.text_( class: "archimate-relationship-name", x: pt.x, y: pt.y, "text-anchor" => "middle", style: css_style.text ) do xml.text name end end |