Class: Dimensional::Enum::Attribute

Inherits:
Object
  • Object
show all
Defined in:
lib/dimensional/enum/attribute.rb

Instance Method Summary collapse

Constructor Details

#initialize(enum_attr_key, enum_attribute) ⇒ Attribute

Returns a new instance of Attribute.



7
8
9
10
# File 'lib/dimensional/enum/attribute.rb', line 7

def initialize( enum_attr_key, enum_attribute )
  @enum_attr_key  = enum_attr_key
  @enum_attribute = enum_attribute
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



56
57
58
59
60
61
# File 'lib/dimensional/enum/attribute.rb', line 56

def method_missing( method, *args, &block )
  if @enum_attribute[label].has_key? method
    return @enum_attribute[label][method]
  end
  super
end

Instance Method Details

#<=>(other) ⇒ Object



16
17
18
# File 'lib/dimensional/enum/attribute.rb', line 16

def <=>( other )
  to_s <=> other
end

#==(other) ⇒ Object



12
13
14
# File 'lib/dimensional/enum/attribute.rb', line 12

def ==( other )
  to_s == other
end

#idObject Also known as: value



20
21
22
23
24
# File 'lib/dimensional/enum/attribute.rb', line 20

def id
  @enum_attribute[label][:id]
rescue
  nil
end

#labelObject



32
33
34
35
36
# File 'lib/dimensional/enum/attribute.rb', line 32

def label
  @enum_attr_key.to_sym
rescue
  nil
end

#nameObject



26
27
28
29
30
# File 'lib/dimensional/enum/attribute.rb', line 26

def name
  @enum_attribute[label][:name]
rescue
  nil
end

#to_iObject



50
51
52
# File 'lib/dimensional/enum/attribute.rb', line 50

def to_i
  id.to_i
end

#to_sObject



42
43
44
# File 'lib/dimensional/enum/attribute.rb', line 42

def to_s
  to_str
end

#to_strObject



38
39
40
# File 'lib/dimensional/enum/attribute.rb', line 38

def to_str
  label.to_s
end

#to_symObject



46
47
48
# File 'lib/dimensional/enum/attribute.rb', line 46

def to_sym
  label.to_sym
end