Class: Playbook::PbKit::Base

Inherits:
Object
  • Object
show all
Defined in:
app/pb_kits/playbook/pb_kit/base.rb

Instance Method Summary collapse

Instance Method Details

#adjusted_value(value, adjusted_value, default_value) ⇒ Object



53
54
55
# File 'app/pb_kits/playbook/pb_kit/base.rb', line 53

def adjusted_value(value, adjusted_value, default_value)
  is_set?(value) ? adjusted_value : default_value
end

#aria(ui_aria = {}) ⇒ Object

Default props =============


7
8
9
# File 'app/pb_kits/playbook/pb_kit/base.rb', line 7

def aria(ui_aria = {})
  merge_value(configured_aria, ui_aria)
end

#classname(ui_classes = "") ⇒ Object



11
12
13
# File 'app/pb_kits/playbook/pb_kit/base.rb', line 11

def classname(ui_classes = "")
  concat_value(configured_classname, ui_classes)
end

#concat_value(value, value2) ⇒ Object



57
58
59
# File 'app/pb_kits/playbook/pb_kit/base.rb', line 57

def concat_value(value, value2)
  is_set?(value) ? value2 + " " + value : value2
end

#data(ui_data = {}) ⇒ Object



15
16
17
# File 'app/pb_kits/playbook/pb_kit/base.rb', line 15

def data(ui_data = {})
  merge_value(configured_data, ui_data)
end

#default_value(value, default_value) ⇒ Object

Default value =============


49
50
51
# File 'app/pb_kits/playbook/pb_kit/base.rb', line 49

def default_value(value, default_value)
  is_set?(value) ? value : default_value
end

#false_value(value, false_value = "", true_value = "") ⇒ Object



82
83
84
85
86
87
88
# File 'app/pb_kits/playbook/pb_kit/base.rb', line 82

def false_value(value, false_value = "", true_value = "")
  if is_set?(value)
    is_true?(value) ? true_value : false_value
  else
    false_value
  end
end

#id(ui_id = nil) ⇒ Object



19
20
21
# File 'app/pb_kits/playbook/pb_kit/base.rb', line 19

def id(ui_id = nil)
  default_value(configured_id, ui_id)
end

#is_boolean?(value) ⇒ Boolean

Returns:

  • (Boolean)


36
37
38
# File 'app/pb_kits/playbook/pb_kit/base.rb', line 36

def is_boolean?(value)
  [true, false].include? value
end

#is_integer?(value) ⇒ Boolean

Returns:

  • (Boolean)


32
33
34
# File 'app/pb_kits/playbook/pb_kit/base.rb', line 32

def is_integer?(value)
  value.is_a? Integer
end

#is_set?(value) ⇒ Boolean

Returns:

  • (Boolean)


44
45
46
# File 'app/pb_kits/playbook/pb_kit/base.rb', line 44

def is_set?(value)
  value != default_configuration
end

#is_string?(value) ⇒ Boolean

Returns:

  • (Boolean)


28
29
30
# File 'app/pb_kits/playbook/pb_kit/base.rb', line 28

def is_string?(value)
  value.is_a? String
end

#is_true?(value) ⇒ Boolean

Type checking =============

Returns:

  • (Boolean)


24
25
26
# File 'app/pb_kits/playbook/pb_kit/base.rb', line 24

def is_true?(value)
  is_boolean?(value) && value == true
end

#merge_value(value, value2) ⇒ Object



61
62
63
64
# File 'app/pb_kits/playbook/pb_kit/base.rb', line 61

def merge_value(value, value2)
  value2 ||= {}
  is_set?(value) ? value.merge(value2) : value2
end

#one_of?(value, options = []) ⇒ Boolean

Returns:

  • (Boolean)


40
41
42
# File 'app/pb_kits/playbook/pb_kit/base.rb', line 40

def one_of?(value, options = [])
  options.include? value
end

#one_of_value(value, options = [], default = "") ⇒ Object



66
67
68
69
70
71
72
# File 'app/pb_kits/playbook/pb_kit/base.rb', line 66

def one_of_value(value, options = [], default = "")
  if is_set?(value)
    options.include?(value) ? value : default
  else
    default
  end
end

#true_value(value, true_value = "", false_value = "") ⇒ Object



74
75
76
77
78
79
80
# File 'app/pb_kits/playbook/pb_kit/base.rb', line 74

def true_value(value, true_value = "", false_value = "")
  if is_set?(value)
    is_true?(value) ? true_value : false_value
  else
    false_value
  end
end