Module: Ea::Sources::Xmi::ExtensionStyleParser
- Defined in:
- lib/ea/sources/xmi/extension_style_parser.rb
Overview
Parses EA's packed style string from
xmi:Extension/
Defined Under Namespace
Classes: Style
Class Method Summary collapse
- .int(value) ⇒ Object
- .parse(style_string) ⇒ Object
- .scale_font_size(value) ⇒ Object
- .split_pairs(str) ⇒ Object
-
.tri_state_icon(value) ⇒ Object
HideIcon tri-state: "1" → :hidden, "0" → :shown, missing → nil (use the diagram default, which EA treats as hidden in practice).
- .truthy?(value) ⇒ Boolean
Class Method Details
.int(value) ⇒ Object
58 59 60 61 62 63 64 |
# File 'lib/ea/sources/xmi/extension_style_parser.rb', line 58 def int(value) return nil if value.nil? || value.empty? Integer(value) rescue ArgumentError nil end |
.parse(style_string) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/ea/sources/xmi/extension_style_parser.rb', line 12 def parse(style_string) return Style.new if style_string.nil? || style_string.empty? kv = split_pairs(style_string) Style.new( background_color: int(kv["BCol"]), line_color: int(kv["LCol"]), line_width: int(kv["LWth"] || kv["LWidth"]), font_family: kv["font"], font_size: scale_font_size(kv["fontsz"]), bold: truthy?(kv["bold"]), italic: truthy?(kv["italic"]), underline: truthy?(kv["ul"]), black: truthy?(kv["black"]), hide_icon: tri_state_icon(kv["HideIcon"]), show_tagged_values: truthy?(kv["Tag"]), duid: kv["DUID"], soid: kv["SOID"], eoid: kv["EOID"], mode: int(kv["Mode"]), color: int(kv["Color"]), hidden: truthy?(kv["Hidden"]), raw: style_string ) end |
.scale_font_size(value) ⇒ Object
70 71 72 73 74 75 76 77 |
# File 'lib/ea/sources/xmi/extension_style_parser.rb', line 70 def scale_font_size(value) return 13 if value.nil? || value.empty? pct = int(value) return 13 if pct.nil? || pct.zero? (pct * 13 / 100).round end |
.split_pairs(str) ⇒ Object
49 50 51 52 53 54 55 56 |
# File 'lib/ea/sources/xmi/extension_style_parser.rb', line 49 def split_pairs(str) str.split(";").filter_map do |pair| next nil unless pair.include?("=") key, value = pair.split("=", 2) [key, value] if key && value && !value.empty? end.to_h end |
.tri_state_icon(value) ⇒ Object
HideIcon tri-state: "1" → :hidden, "0" → :shown, missing → nil (use the diagram default, which EA treats as hidden in practice).
41 42 43 44 45 46 47 |
# File 'lib/ea/sources/xmi/extension_style_parser.rb', line 41 def tri_state_icon(value) return nil if value.nil? || value.empty? return :hidden if value == "1" || value == "true" || value == "-1" return :shown if value == "0" nil end |
.truthy?(value) ⇒ Boolean
66 67 68 |
# File 'lib/ea/sources/xmi/extension_style_parser.rb', line 66 def truthy?(value) value == "1" || value == "true" || value == "-1" end |