Class: Playbook::PbStatChange::StatChange

Inherits:
Playbook::PbKit::Base show all
Defined in:
app/pb_kits/playbook/pb_stat_change/stat_change.rb

Constant Summary collapse

PROPS =
%i[configured_change
configured_classname
configured_data
configured_id
configured_value].freeze

Instance Method Summary collapse

Methods inherited from Playbook::PbKit::Base

#adjusted_value, #aria, #classname, #concat_value, #data, #default_value, #false_value, #id, #is_boolean?, #is_integer?, #is_set?, #is_string?, #is_true?, #merge_value, #one_of?, #one_of_value, #true_value

Constructor Details

#initialize(change: default_configuration, classname: default_configuration, data: default_configuration, id: default_configuration, value: default_configuration) ⇒ StatChange

Returns a new instance of StatChange.



12
13
14
15
16
17
18
19
20
21
22
# File 'app/pb_kits/playbook/pb_stat_change/stat_change.rb', line 12

def initialize(change: default_configuration,
               classname: default_configuration,
               data: default_configuration,
               id: default_configuration,
               value: default_configuration)
  self.configured_change = change
  self.configured_classname = classname
  self.configured_data = data
  self.configured_id = id
  self.configured_value = value
end

Instance Method Details

#changeObject



24
25
26
27
# File 'app/pb_kits/playbook/pb_stat_change/stat_change.rb', line 24

def change
  change_options = %w[neutral increase decrease]
  one_of_value(configured_change, change_options, "neutral")
end

#display_iconObject



49
50
51
52
53
54
55
56
# File 'app/pb_kits/playbook/pb_stat_change/stat_change.rb', line 49

def display_icon
  if !icon.nil?
    pb_icon = Playbook::PbIcon::Icon.new(icon: icon, fixed_width: true)
    ApplicationController.renderer.render(partial: pb_icon, as: :object)
  else
    ""
  end
end

#display_valueObject



62
63
64
65
66
67
68
# File 'app/pb_kits/playbook/pb_stat_change/stat_change.rb', line 62

def display_value
  pb_icon_element = Playbook::PbBody::Body.new(status: status) do
    display_icon +
      value
  end
  ApplicationController.renderer.render(partial: pb_icon_element, as: :object)
end

#iconObject



40
41
42
43
44
45
46
47
# File 'app/pb_kits/playbook/pb_stat_change/stat_change.rb', line 40

def icon
  case change
  when "increase"
    "arrow-up"
  when "decrease"
    "arrow-down"
  end
end

#kit_classObject



70
71
72
73
74
75
76
# File 'app/pb_kits/playbook/pb_stat_change/stat_change.rb', line 70

def kit_class
  stat_options = [
    "pb_stat_change_kit",
    status,
  ]
  stat_options.join("_")
end

#statusObject



29
30
31
32
33
34
35
36
37
38
# File 'app/pb_kits/playbook/pb_stat_change/stat_change.rb', line 29

def status
  case change
  when "increase"
    "positive"
  when "decrease"
    "negative"
  else
    "neutral"
  end
end

#to_partial_pathObject



78
79
80
# File 'app/pb_kits/playbook/pb_stat_change/stat_change.rb', line 78

def to_partial_path
  "pb_stat_change/stat_change"
end

#valueObject



58
59
60
# File 'app/pb_kits/playbook/pb_stat_change/stat_change.rb', line 58

def value
  default_value(configured_value, "")
end