Class: Dedalus::PatternLibrary::PeriodicTableEntry

Inherits:
Molecule show all
Defined in:
lib/dedalus/pattern_library/molecules/periodic_table_entry.rb

Instance Attribute Summary collapse

Attributes inherited from Element

#height_percent, #offset, #position, #shown, #width_percent, #z_order

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Molecule

#hover

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.



6
7
8
# File 'lib/dedalus/pattern_library/molecules/periodic_table_entry.rb', line 6

def color
  @color
end

#element_nameObject

Returns the value of attribute element_name.



4
5
6
# File 'lib/dedalus/pattern_library/molecules/periodic_table_entry.rb', line 4

def element_name
  @element_name
end

#kindObject

Returns the value of attribute kind.



5
6
7
# File 'lib/dedalus/pattern_library/molecules/periodic_table_entry.rb', line 5

def kind
  @kind
end

#scaleObject

Returns the value of attribute scale.



7
8
9
# File 'lib/dedalus/pattern_library/molecules/periodic_table_entry.rb', line 7

def scale
  @scale
end

Class Method Details

.descriptionObject



58
59
60
# File 'lib/dedalus/pattern_library/molecules/periodic_table_entry.rb', line 58

def self.description
  "a high-level view of an element"
end

.example_dataObject



62
63
64
65
66
67
# File 'lib/dedalus/pattern_library/molecules/periodic_table_entry.rb', line 62

def self.example_data
  {
    element_abbreviation: "Ht",
    element_name: "Huge Text"
  }
end

Instance Method Details

#abbreviationObject



21
22
23
24
25
26
27
# File 'lib/dedalus/pattern_library/molecules/periodic_table_entry.rb', line 21

def abbreviation
  if element_name.match(/ /) #split(" ").count > 0
    element_name.split(" ").map(&:first).join.capitalize
  else
    element_name.slice(0,2).capitalize
  end
end

#background_colorObject



49
50
51
52
53
54
55
56
# File 'lib/dedalus/pattern_library/molecules/periodic_table_entry.rb', line 49

def background_color
  if color
    c = Palette.decode_color(color) if color.is_a?(String)
    c.darken
  else
    Palette.gray
  end
end

#clickObject



29
30
31
# File 'lib/dedalus/pattern_library/molecules/periodic_table_entry.rb', line 29

def click
  view.route_to(element_name)
end

#heightObject



45
46
47
# File 'lib/dedalus/pattern_library/molecules/periodic_table_entry.rb', line 45

def height
  300 * scale
end

#marginObject



33
34
35
# File 'lib/dedalus/pattern_library/molecules/periodic_table_entry.rb', line 33

def margin
  15 * scale
end

#paddingObject



37
38
39
# File 'lib/dedalus/pattern_library/molecules/periodic_table_entry.rb', line 37

def padding
  30 * scale
end

#showObject



9
10
11
12
13
14
15
# File 'lib/dedalus/pattern_library/molecules/periodic_table_entry.rb', line 9

def show
  [
    HugeText.new(text: abbreviation, scale: scale),
    LargeText.new(text: element_name, scale: scale),
    TinyText.new(text: kind, scale: scale)
  ]
end

#widthObject



41
42
43
# File 'lib/dedalus/pattern_library/molecules/periodic_table_entry.rb', line 41

def width
  260 * scale
end