Class: Systems::Entry

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/lingohub_shield/systems/entry.rb

Constant Summary collapse

LH =
'#575757'
GREEN =
'#45cb14'
YELLOW =
'#c0cc14'
RED =
'#cc2114'
GREEN_THRESHOLD =
95
YELLOW_THRESHOLD =
90

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(label, percentage, padding = 18) ⇒ Entry

Initializes the shield entry

Parameters:

  • label, (Symbol)

    the text that should be written within the entries container in the shield

  • percentage, (Integer)

    value that determines the container background color

  • padding, (Integer)

    space from the container’s left and right edges to the label



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/lingohub_shield/systems/entry.rb', line 20

def initialize(label, percentage, padding = 18)
  @label = label
  @percentage = percentage
  @padding = padding

  @font_size = 15
  @font_family = 'helvetica'
  @font_style = Magick::NormalStyle
  @font_gravity = Magick::WestGravity
  @stroke = 'transparent'
  @stroke_width = 1
  @color = 'white'
  @width = get_text_width

  if percentage
    @font_weight = Magick::NormalWeight
  else
    @font_weight = Magick::BoldWeight
  end
end

Instance Attribute Details

#colorObject (readonly)

Returns the value of attribute color.



14
15
16
# File 'lib/lingohub_shield/systems/entry.rb', line 14

def color
  @color
end

#font_familyObject (readonly)

Returns the value of attribute font_family.



14
15
16
# File 'lib/lingohub_shield/systems/entry.rb', line 14

def font_family
  @font_family
end

#font_gravityObject (readonly)

Returns the value of attribute font_gravity.



14
15
16
# File 'lib/lingohub_shield/systems/entry.rb', line 14

def font_gravity
  @font_gravity
end

#font_sizeObject (readonly)

Returns the value of attribute font_size.



14
15
16
# File 'lib/lingohub_shield/systems/entry.rb', line 14

def font_size
  @font_size
end

#font_styleObject (readonly)

Returns the value of attribute font_style.



14
15
16
# File 'lib/lingohub_shield/systems/entry.rb', line 14

def font_style
  @font_style
end

#font_weightObject (readonly)

Returns the value of attribute font_weight.



14
15
16
# File 'lib/lingohub_shield/systems/entry.rb', line 14

def font_weight
  @font_weight
end

#labelObject (readonly)

Returns the value of attribute label.



14
15
16
# File 'lib/lingohub_shield/systems/entry.rb', line 14

def label
  @label
end

#percentageObject (readonly)

Returns the value of attribute percentage.



14
15
16
# File 'lib/lingohub_shield/systems/entry.rb', line 14

def percentage
  @percentage
end

#strokeObject (readonly)

Returns the value of attribute stroke.



14
15
16
# File 'lib/lingohub_shield/systems/entry.rb', line 14

def stroke
  @stroke
end

#stroke_widthObject (readonly)

Returns the value of attribute stroke_width.



14
15
16
# File 'lib/lingohub_shield/systems/entry.rb', line 14

def stroke_width
  @stroke_width
end

#widthObject (readonly)

Returns the value of attribute width.



14
15
16
# File 'lib/lingohub_shield/systems/entry.rb', line 14

def width
  @width
end

Instance Method Details

#<=>(another) ⇒ Object

enables sorting of entries alphabetically by label



55
56
57
# File 'lib/lingohub_shield/systems/entry.rb', line 55

def <=>(another)
  label <=> another.label
end

#background_colorObject

returns the appropriate background color depending on the percentage



42
43
44
45
46
47
48
49
50
51
52
# File 'lib/lingohub_shield/systems/entry.rb', line 42

def background_color
  if percentage.nil?
    LH
  elsif percentage > GREEN_THRESHOLD
    GREEN
  elsif percentage > YELLOW_THRESHOLD
    YELLOW
  else
    RED
  end
end