Module: Scale::Types::Base

Defined Under Namespace

Modules: ClassMethods

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#valueObject (readonly)

Returns the value of attribute value.



5
6
7
# File 'lib/scale/base.rb', line 5

def value
  @value
end

Class Method Details

.included(base) ⇒ Object



45
46
47
48
# File 'lib/scale/base.rb', line 45

def self.included(base)
  base.extend(ClassMethods)
  base.const_set(:TYPE_NAME, base.name)
end

Instance Method Details

#==(other) ⇒ Object



11
12
13
# File 'lib/scale/base.rb', line 11

def ==(other)
  self.class == other.class && self.value == other.value
end

#initialize(value) ⇒ Object



7
8
9
# File 'lib/scale/base.rb', line 7

def initialize(value)
  @value = value
end

#to_humanObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/scale/base.rb', line 15

def to_human
  if @value.class == ::Hash
    @value.transform_values do |v|
      if v.class.included_modules.include?(Base)
        v.to_human
      else
        v
      end
    end.transform_keys(&:to_sym)
  elsif @value.class == ::Array
    @value.map do |v|
      if v.class.included_modules.include?(Base)
        v.to_human
      else
        v
      end
    end
  elsif @value.class.include?(Base)
    @value.to_human
  else
    @value
  end
end