Class: Odca::Overlays::LabelOverlay::InputValidator

Inherits:
Object
  • Object
show all
Defined in:
lib/odca/overlays/label_overlay.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attr_name:, value:) ⇒ InputValidator

Returns a new instance of InputValidator.



74
75
76
77
78
79
80
81
# File 'lib/odca/overlays/label_overlay.rb', line 74

def initialize(attr_name:, value:)
  if attr_name.strip.empty?
    raise 'Attribute name is expected to be non empty String'
  end

  @attr_name = attr_name
  @value = value
end

Instance Attribute Details

#attr_nameObject (readonly)

Returns the value of attribute attr_name.



72
73
74
# File 'lib/odca/overlays/label_overlay.rb', line 72

def attr_name
  @attr_name
end

#valueObject (readonly)

Returns the value of attribute value.



72
73
74
# File 'lib/odca/overlays/label_overlay.rb', line 72

def value
  @value
end

Instance Method Details

#callObject



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/odca/overlays/label_overlay.rb', line 83

def call
  category = Odca::NullValue.new
  label = Odca::NullValue.new

  splited = value.split('|')
  case splited.length
  when 1
    label = value.strip
  when 2
    category = splited[0].strip
    label = splited[1].strip
  end

  {
    attr_name: attr_name.strip,
    category: category,
    label: label
  }
end