Class: Archimate::DataModel::Font

Inherits:
Object
  • Object
show all
Includes:
Comparison
Defined in:
lib/archimate/data_model/font.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Comparison

#==, #[], #dig, #each, #hash, included, #inspect, #pretty_print, #to_h

Constructor Details

#initialize(name: nil, size: nil, style: nil, font_data: nil) ⇒ Font

Returns a new instance of Font.



39
40
41
42
43
44
# File 'lib/archimate/data_model/font.rb', line 39

def initialize(name: nil, size: nil, style: nil, font_data: nil)
  @name = name
  @size = size.nil? ? nil : size.to_f
  @style = style.nil? ? nil : style.to_i
  @font_data = font_data
end

Instance Attribute Details

#font_dataString, NilClass (readonly)

Returns:

  • (String, NilClass)


20
# File 'lib/archimate/data_model/font.rb', line 20

model_attr :font_data, default: nil

#nameString, NilClass (readonly)

Returns:

  • (String, NilClass)


10
# File 'lib/archimate/data_model/font.rb', line 10

model_attr :name, default: nil

#sizeFloat, NilClass (readonly)

Returns:

  • (Float, NilClass)


13
# File 'lib/archimate/data_model/font.rb', line 13

model_attr :size, default: nil

#styleInt, NilClass (readonly)

TODO:

make this an enum

Returns:

  • (Int, NilClass)


17
# File 'lib/archimate/data_model/font.rb', line 17

model_attr :style, default: nil

Class Method Details

.archi_font_string(str) ⇒ Object

TODO:

move this to the archi file reader

Archi font strings look like this:

"1|Arial            |14.0|0|WINDOWS|1|0  |0|0|0|0  |0 |0|0|1|0|0|0|0 |Arial"
"1|Arial            |8.0 |0|WINDOWS|1|0  |0|0|0|0  |0 |0|0|1|0|0|0|0 |Arial"
"1|Segoe UI Semibold|12.0|2|WINDOWS|1|-16|0|0|0|600|-1|0|0|0|3|2|1|34|Segoe UI Semibold"
"1|Times New Roman  |12.0|3|WINDOWS|1|-16|0|0|0|700|-1|0|0|0|3|2|1|18|Times New Roman"


28
29
30
31
32
33
34
35
36
37
# File 'lib/archimate/data_model/font.rb', line 28

def self.archi_font_string(str)
  return nil if str.nil?
  font_parts = str.split("|")
  DataModel::Font.new(
    name: font_parts[1],
    size: font_parts[2].to_f,
    style: font_parts[3].to_i,
    font_data: str
  )
end

Instance Method Details

#style_stringObject

TODO:

this isn’t standard

Move to file format



60
61
62
63
64
65
66
67
68
69
# File 'lib/archimate/data_model/font.rb', line 60

def style_string
  case style
  when 1
    "italic"
  when 2
    "bold"
  when 3
    "bold|italic"
  end
end

#to_archi_fontObject



50
51
52
53
54
55
56
# File 'lib/archimate/data_model/font.rb', line 50

def to_archi_font
  font_data ||
    [
      1, name, size, style, "WINDOWS", 1, 0, 0, 0, 0, 0, 0,
      0, 0, 1, 0, 0, 0, 0, name
    ].map(&:to_s).join("|")
end

#to_sObject



46
47
48
# File 'lib/archimate/data_model/font.rb', line 46

def to_s
  "Font(name: #{name}, size: #{size}, style: #{style})"
end