Class: Graphomaton::State

Inherits:
Data
  • Object
show all
Defined in:
lib/graphomaton/model.rb,
sig/graphomaton.rbs

Constant Summary collapse

MISSING =
Object.new.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id:, x:, y:, label:, style:, metadata:, shape:, kind:) ⇒ State

Returns a new instance of State.



111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/graphomaton/model.rb', line 111

def initialize(id:, x:, y:, label:, style:, metadata:, shape:, kind:)
  super(
    id: ModelValue.copy(id),
    x: x,
    y: y,
    label: ModelValue.copy(label),
    style: ModelValue.copy(style),
    metadata: ModelValue.copy(),
    shape: ModelValue.copy(shape),
    kind: kind.nil? ? nil : kind.to_sym
  )
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id

Returns:

  • (Object)

    the current value of id



108
109
110
# File 'lib/graphomaton/model.rb', line 108

def id
  @id
end

#kindObject (readonly)

Returns the value of attribute kind

Returns:

  • (Object)

    the current value of kind



108
109
110
# File 'lib/graphomaton/model.rb', line 108

def kind
  @kind
end

#labelObject (readonly)

Returns the value of attribute label

Returns:

  • (Object)

    the current value of label



108
109
110
# File 'lib/graphomaton/model.rb', line 108

def label
  @label
end

#metadataObject (readonly)

Returns the value of attribute metadata

Returns:

  • (Object)

    the current value of metadata



108
109
110
# File 'lib/graphomaton/model.rb', line 108

def 
  @metadata
end

#shapeObject (readonly)

Returns the value of attribute shape

Returns:

  • (Object)

    the current value of shape



108
109
110
# File 'lib/graphomaton/model.rb', line 108

def shape
  @shape
end

#styleObject (readonly)

Returns the value of attribute style

Returns:

  • (Object)

    the current value of style



108
109
110
# File 'lib/graphomaton/model.rb', line 108

def style
  @style
end

#xObject (readonly)

Returns the value of attribute x

Returns:

  • (Object)

    the current value of x



108
109
110
# File 'lib/graphomaton/model.rb', line 108

def x
  @x
end

#yObject (readonly)

Returns the value of attribute y

Returns:

  • (Object)

    the current value of y



108
109
110
# File 'lib/graphomaton/model.rb', line 108

def y
  @y
end

Instance Method Details

#[](key) ⇒ Object



124
125
126
127
128
129
130
# File 'lib/graphomaton/model.rb', line 124

def [](key)
  return id if key == :name || key == :id

  public_send(key)
rescue NoMethodError
  nil
end

#fetch(key, default = MISSING) ⇒ Object

Raises:

  • (KeyError)


132
133
134
135
136
137
138
# File 'lib/graphomaton/model.rb', line 132

def fetch(key, default = MISSING)
  value = self[key]
  return value unless value.nil?
  return default unless default.equal?(MISSING)

  raise KeyError, "key not found: #{key.inspect}"
end

#to_hObject



140
141
142
143
144
145
146
147
148
# File 'lib/graphomaton/model.rb', line 140

def to_h
  output = { name: id, x: x, y: y }
  output[:label] = label unless label.nil?
  output[:style] = style unless style.nil?
  output[:metadata] =  unless .nil?
  output[:shape] = shape unless shape.nil?
  output[:kind] = kind unless kind.nil?
  output
end