Class: RailroadDiagrams::Start
- Inherits:
-
DiagramItem
- Object
- DiagramItem
- RailroadDiagrams::Start
- Defined in:
- lib/railroad_diagrams/start.rb
Instance Attribute Summary
Attributes inherited from DiagramItem
#attrs, #children, #down, #height, #needs_space, #up, #width
Instance Method Summary collapse
- #format(x, y, _width) ⇒ Object
-
#initialize(type = 'simple', label: nil) ⇒ Start
constructor
A new instance of Start.
- #text_diagram ⇒ Object
- #to_s ⇒ Object
Methods inherited from DiagramItem
#add, #to_str, #walk, #write_svg
Constructor Details
#initialize(type = 'simple', label: nil) ⇒ Start
Returns a new instance of Start.
5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/railroad_diagrams/start.rb', line 5 def initialize(type = 'simple', label: nil) super('g') @width = if label [20, (label.length * CHAR_WIDTH) + 10].max else 20 end @up = 10 @down = 10 @type = type @label = label end |
Instance Method Details
#format(x, y, _width) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/railroad_diagrams/start.rb', line 23 def format(x, y, _width) path = Path.new(x, y - 10) if @type == 'complex' path.down(20).m(0, -10).right(@width).add(self) else path.down(20).m(10, -20).down(20).m(-10, -10).right(@width).add(self) end if @label DiagramItem.new( 'text', attrs: { 'x' => x, 'y' => y - 15, 'style' => 'text-anchor:start' }, text: @label ).add(self) end self end |
#text_diagram ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/railroad_diagrams/start.rb', line 44 def text_diagram cross, line, tee_right = TextDiagram.get_parts(%w[cross line tee_right]) start = if @type == 'simple' tee_right + cross + line else tee_right + line end label_td = TextDiagram.new(0, 0, []) if @label label_td = TextDiagram.new(0, 0, [@label]) start = TextDiagram.pad_r(start, label_td.width, line) end start_td = TextDiagram.new(0, 0, [start]) label_td.append_below(start_td, [], move_entry: true, move_exit: true) end |
#to_s ⇒ Object
19 20 21 |
# File 'lib/railroad_diagrams/start.rb', line 19 def to_s "Start(#{@type}, label=#{@label})" end |