Module: Vinber::Klass

Defined in:
lib/vinber/vinber_klass.rb

Instance Method Summary collapse

Instance Method Details

#vinber_list(attribute, options = {}, &block) ⇒ Object

Raises:



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/vinber/vinber_klass.rb', line 4

def vinber_list(attribute, options = {}, &block)
  klass = self
  raise VinberUndefined, "Vinber was undefined in #{klass.name}" unless klass.vinber_defined?

  need_tanslate = options.fetch(:t){true}
  if klass.vinber_defined? attribute
    attribute_vinber = klass.defined_vinbers[attribute.to_s]
    return attribute_vinber unless attribute_vinber.is_a?(Hash)

    attribute_vinber.map do |key, value|
      key = Vinber::Translate.new(klass, attribute, key).to_s if need_tanslate
      block_given?? block.call(key, value) : [key, value]
    end
  end.to_a
end

#vinber_value(attribute, key_or_value) ⇒ Object

Raises:



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/vinber/vinber_klass.rb', line 20

def vinber_value(attribute, key_or_value)
  klass = self
  raise VinberUndefined, "Vinber was undefined in #{klass.name}" unless klass.vinber_defined?

  if key_or_value.is_a?(Symbol)
    key = key_or_value
  else
    attribute_vinber = defined_vinbers || {}
    key = attribute_vinber[attribute.to_s].key key_or_value
  end

  Vinber::Translate.new(klass, attribute, key).to_s
end