Class: KwykTree::Unit

Inherits:
Object
  • Object
show all
Defined in:
lib/kwyktree/unit.rb

Direct Known Subclasses

Concept, Implementation

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(unit) ⇒ Unit

Returns a new instance of Unit.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/kwyktree/unit.rb', line 6

def initialize(unit)
  if unit['name']
    @name = unit['name']
  else
    raise "unit needs a name"
  end

  @details = {}
  @details["anki"] = unit['anki'] || false
  @details["grok"] = unit['grok'] || false
  @desc = unit['desc'] || ""
  @url = unit['url'] if unit['url']
  @deps = unit['deps'] || []
  @deps.each do |l|
    l.downcase!
  end
  @title = unit['title'] || pretty_name
end

Instance Attribute Details

#depsObject (readonly)

Returns the value of attribute deps.



5
6
7
# File 'lib/kwyktree/unit.rb', line 5

def deps
  @deps
end

#urlObject (readonly)

Returns the value of attribute url.



5
6
7
# File 'lib/kwyktree/unit.rb', line 5

def url
  @url
end

Instance Method Details

#graphviz_attributesObject



38
39
40
41
42
43
44
45
46
# File 'lib/kwyktree/unit.rb', line 38

def graphviz_attributes
  hsh = {
    tooltip: @title,
    label: graphviz_record_label,
    shape: graphviz_record_shape
  }
  hsh[:URL] = @url if @url
  hsh
end

#graphviz_idObject



34
35
36
# File 'lib/kwyktree/unit.rb', line 34

def graphviz_id
  "#{type}.#{@name.downcase.tr(' ', '_')}"
end

#graphviz_record_labelObject



29
30
31
32
# File 'lib/kwyktree/unit.rb', line 29

def graphviz_record_label
  # TODO: add desc
  "{#{@title}#{graphviz_details}}"
end

#graphviz_record_shapeObject



48
49
50
# File 'lib/kwyktree/unit.rb', line 48

def graphviz_record_shape
  raise "unit needs to be subclassed!"
end

#typeObject



25
26
27
# File 'lib/kwyktree/unit.rb', line 25

def type
  raise "unit needs to be subclassed!"
end