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.



123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/graphomaton/model.rb', line 123

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

#id ⇒ Object (readonly)

Returns the value of attribute id

Returns:

  • (Object) —

    the current value of id



120
121
122
# File 'lib/graphomaton/model.rb', line 120

def id
  @id
end

#kind ⇒ Object (readonly)

Returns the value of attribute kind

Returns:

  • (Object) —

    the current value of kind



120
121
122
# File 'lib/graphomaton/model.rb', line 120

def kind
  @kind
end

#label ⇒ Object (readonly)

Returns the value of attribute label

Returns:

  • (Object) —

    the current value of label



120
121
122
# File 'lib/graphomaton/model.rb', line 120

def label
  @label
end

#metadata ⇒ Object (readonly)

Returns the value of attribute metadata

Returns:

  • (Object) —

    the current value of metadata



120
121
122
# File 'lib/graphomaton/model.rb', line 120

def 
  @metadata
end

#shape ⇒ Object (readonly)

Returns the value of attribute shape

Returns:

  • (Object) —

    the current value of shape



120
121
122
# File 'lib/graphomaton/model.rb', line 120

def shape
  @shape
end

#style ⇒ Object (readonly)

Returns the value of attribute style

Returns:

  • (Object) —

    the current value of style



120
121
122
# File 'lib/graphomaton/model.rb', line 120

def style
  @style
end

#x ⇒ Object (readonly)

Returns the value of attribute x

Returns:

  • (Object) —

    the current value of x



120
121
122
# File 'lib/graphomaton/model.rb', line 120

def x
  @x
end

#y ⇒ Object (readonly)

Returns the value of attribute y

Returns:

  • (Object) —

    the current value of y



120
121
122
# File 'lib/graphomaton/model.rb', line 120

def y
  @y
end

Instance Method Details

#[](key) ⇒ Object



136
137
138
139
140
141
142
# File 'lib/graphomaton/model.rb', line 136

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

  public_send(key)
rescue NoMethodError
  nil
end

#fetch(key, default = MISSING) ⇒ Object

Raises:

  • (KeyError)


144
145
146
147
148
149
150
# File 'lib/graphomaton/model.rb', line 144

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_h ⇒ Object



152
153
154
155
156
157
158
159
160
# File 'lib/graphomaton/model.rb', line 152

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