Class: Label

Inherits:
Object
  • Object
show all
Defined in:
lib/bud/labeling/labeling.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(mod) ⇒ Label

Returns a new instance of Label.



207
208
209
210
211
212
213
214
215
216
217
218
219
# File 'lib/bud/labeling/labeling.rb', line 207

def initialize(mod)
  @report = nil
  @mod = Object.const_get(mod)
  if @mod.class == Class
    nc = new_class_from_class(@mod)
  elsif @mod.class == Module
    nc = new_class(@mod)
  else
    raise "#{mod} neither class nor module"
  end
  @f = nc.new
  @f.tick
end

Instance Attribute Details

#fObject (readonly)

Returns the value of attribute f.



205
206
207
# File 'lib/bud/labeling/labeling.rb', line 205

def f
  @f
end

Instance Method Details

#disjunction(l, r) ⇒ Object



246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
# File 'lib/bud/labeling/labeling.rb', line 246

def disjunction(l, r)
  both = [l, r]
  if both.include? "D"
    "D"
  elsif both.include? "N"
    if both.include? "A"
      return "D"
    else
      return "N"
    end
  elsif both.include? "A"
    return "A"
  else
    return "Bot"
  end
end

#internal_tabsObject



277
278
279
280
281
282
283
# File 'lib/bud/labeling/labeling.rb', line 277

def internal_tabs
  cls = Class.new do
    include Bud
    include MetaMods
  end
  cls.new.tables.keys
end

#new_class(mod) ⇒ Object



263
264
265
266
267
268
269
# File 'lib/bud/labeling/labeling.rb', line 263

def new_class(mod)
  Class.new do
    include Bud
    include MetaMods
    include mod
  end
end

#new_class_from_class(cls) ⇒ Object



271
272
273
274
275
# File 'lib/bud/labeling/labeling.rb', line 271

def new_class_from_class(cls)
  Class.new(cls) do
    include MetaMods
  end
end

#output_reportObject



225
226
227
228
229
230
231
232
233
# File 'lib/bud/labeling/labeling.rb', line 225

def output_report
  validate
  rep = {}
  @report.each do |from, to, path, labels, reason, final|
    rep[to] ||= "Bot"
    rep[to] = disjunction(rep[to], final.last)
  end
  rep
end

#path_reportObject



235
236
237
238
239
240
241
242
243
244
# File 'lib/bud/labeling/labeling.rb', line 235

def path_report
  validate
  zips = {}
  @report.each do |from, to, path, labels, reason, final|
    zips[to] ||= {}
    zips[to][from] ||= "Bot"
    zips[to][from] = disjunction(zips[to][from], final.last)
  end
  zips
end

#validateObject



221
222
223
# File 'lib/bud/labeling/labeling.rb', line 221

def validate
  @report = @f.validate if @report.nil?
end

#write_graph(fmt = :pdf) ⇒ Object



285
286
287
# File 'lib/bud/labeling/labeling.rb', line 285

def write_graph(fmt=:pdf)
  f.finish(internal_tabs, "#{@mod.to_s}.#{fmt}", fmt)
end