Class: Dedalus::PatternLibrary::LibraryEntry

Inherits:
Organism show all
Defined in:
lib/dedalus/pattern_library/organisms/library_entry.rb

Instance Attribute Summary collapse

Attributes inherited from Element

#height, #height_percent, #margin, #offset, #position, #shown, #width, #width_percent, #z_order

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Element

#big_font, #code_font, #draw_bounding_box, #font, #huge_font, #initialize, #record?, #tiny_font, #view, #window

Constructor Details

This class inherits a constructor from Dedalus::Element

Instance Attribute Details

#colorObject

Returns the value of attribute color.



4
5
6
# File 'lib/dedalus/pattern_library/organisms/library_entry.rb', line 4

def color
  @color
end

#descriptionObject

Returns the value of attribute description.



4
5
6
# File 'lib/dedalus/pattern_library/organisms/library_entry.rb', line 4

def description
  @description
end

#itemObject

Returns the value of attribute item.



4
5
6
# File 'lib/dedalus/pattern_library/organisms/library_entry.rb', line 4

def item
  @item
end

#itemsObject

Returns the value of attribute items.



4
5
6
# File 'lib/dedalus/pattern_library/organisms/library_entry.rb', line 4

def items
  @items
end

#show_tableObject

Returns the value of attribute show_table.



4
5
6
# File 'lib/dedalus/pattern_library/organisms/library_entry.rb', line 4

def show_table
  @show_table
end

#subtitleObject

Returns the value of attribute subtitle.



4
5
6
# File 'lib/dedalus/pattern_library/organisms/library_entry.rb', line 4

def subtitle
  @subtitle
end

#titleObject

Returns the value of attribute title.



4
5
6
# File 'lib/dedalus/pattern_library/organisms/library_entry.rb', line 4

def title
  @title
end

Class Method Details

.descriptionObject



49
50
51
# File 'lib/dedalus/pattern_library/organisms/library_entry.rb', line 49

def self.description
  "An entry in a library"
end

.example_dataObject



53
54
55
56
57
58
59
60
61
# File 'lib/dedalus/pattern_library/organisms/library_entry.rb', line 53

def self.example_data
  {
    title: "Welcome",
    subtitle: "world",
    description: "Welcome to this section",
    color: "darkblue",
    items: [ LibraryItemExample.example_data ]
  }
end

.from_item(item) ⇒ Object



6
7
8
# File 'lib/dedalus/pattern_library/organisms/library_entry.rb', line 6

def self.from_item(item)
  new(title: item[:name], subtitle: item[:description], item: item)
end

Instance Method Details

#background_colorObject



41
42
43
44
45
46
47
# File 'lib/dedalus/pattern_library/organisms/library_entry.rb', line 41

def background_color
  if color
    Palette.decode_color(color).lighten
  elsif item && item[:color]
    Palette.decode_color(item[:color])
  end
end

#library_itemsObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/dedalus/pattern_library/organisms/library_entry.rb', line 18

def library_items
  if items
    if show_table
      PeriodicTable.new(elements: items)
    else # items
      items.map do |name:, description:, item_class_name:, item_data:, kind:, color:|
        PeriodicTableEntry.new(
          element_name: name,
          color: color,
          kind: kind)
      end
    end
  elsif item
    LibraryItemExample.new(item)
  else
    []
  end
end

#paddingObject



37
38
39
# File 'lib/dedalus/pattern_library/organisms/library_entry.rb', line 37

def padding
  @padding ||= 40
end

#showObject



10
11
12
13
14
15
16
# File 'lib/dedalus/pattern_library/organisms/library_entry.rb', line 10

def show
  [
    HugeText.new(text: title),
    LargeText.new(text: subtitle),
    TinyText.new(text: description)
  ] + [ library_items ]
end