Class: MetaEnum::Value

Inherits:
Object
  • Object
show all
Defined in:
lib/meta_enum/value.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(number, name, data, type) ⇒ Value

Returns a new instance of Value.



5
6
7
8
9
10
11
# File 'lib/meta_enum/value.rb', line 5

def initialize(number, name, data, type)
  @number = Integer(number)
  @name = name.to_sym
  @data = data
  @type = type
  freeze
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



3
4
5
# File 'lib/meta_enum/value.rb', line 3

def data
  @data
end

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/meta_enum/value.rb', line 3

def name
  @name
end

#numberObject (readonly)

Returns the value of attribute number.



3
4
5
# File 'lib/meta_enum/value.rb', line 3

def number
  @number
end

#typeObject (readonly)

Returns the value of attribute type.



3
4
5
# File 'lib/meta_enum/value.rb', line 3

def type
  @type
end

Instance Method Details

#==(other) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/meta_enum/value.rb', line 13

def ==(other)
  equal?(other) || equal?(type[other])

# type[] will raise for certain bad keys. Those are obviously not equal so return false.
rescue ArgumentError, KeyError
  false
end

#inspectObject



24
25
26
# File 'lib/meta_enum/value.rb', line 24

def inspect
  "#<#{self.class}: #{name}: #{number}, data: #{data.inspect}>"
end

#to_iObject



21
# File 'lib/meta_enum/value.rb', line 21

def to_i; number; end

#to_sObject



22
# File 'lib/meta_enum/value.rb', line 22

def to_s; name.to_s; end