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.



119
120
121
122
123
124
125
126
# File 'lib/odca/overlays/label_overlay.rb', line 119

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.



117
118
119
# File 'lib/odca/overlays/label_overlay.rb', line 117

def attr_name
  @attr_name
end

#valueObject (readonly)

Returns the value of attribute value.



117
118
119
# File 'lib/odca/overlays/label_overlay.rb', line 117

def value
  @value
end

Instance Method Details

#callObject



128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/odca/overlays/label_overlay.rb', line 128

def call
  splited = value.split('|').map(&:strip)

  label = splited.empty? ? Odca::NullValue.new : splited.pop
  categories = splited

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