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
- .truthy?(value) ⇒ Boolean
Class Method Details
.int(value) ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/ea/sources/xmi/extension_style_parser.rb', line 46 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 |
# 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: truthy?(kv["HideIcon"]), 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
58 59 60 61 62 63 64 65 |
# File 'lib/ea/sources/xmi/extension_style_parser.rb', line 58 def scale_font_size(value) return 13 if value.nil? || value.empty? pct = int(value) return 13 if pct.nil? (pct * 13 / 100).round end |
.split_pairs(str) ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'lib/ea/sources/xmi/extension_style_parser.rb', line 37 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 |
.truthy?(value) ⇒ Boolean
54 55 56 |
# File 'lib/ea/sources/xmi/extension_style_parser.rb', line 54 def truthy?(value) value == "1" || value == "true" || value == "-1" end |