Class: Enumbler::Enumble

Inherits:
Object
  • Object
show all
Defined in:
lib/enumbler/enumble.rb

Overview

Class that holds each row of Enumble data.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(enum, id, label: nil, label_column_name: :label, **attributes) ⇒ Enumble

Returns a new instance of Enumble.



8
9
10
11
12
13
14
15
# File 'lib/enumbler/enumble.rb', line 8

def initialize(enum, id, label: nil, label_column_name: :label, **attributes)
  @id = id
  @enum = enum
  @label_column_name = label_column_name
  @label = (label_col_specified? ? attributes[label_column_name] : label) || enum.to_s.dasherize
  @additional_attributes = attributes || {}
  @additional_attributes.merge!({ label: label }) unless label.nil?
end

Instance Attribute Details

#enumObject (readonly)

Returns the value of attribute enum.



6
7
8
# File 'lib/enumbler/enumble.rb', line 6

def enum
  @enum
end

#idObject (readonly)

Returns the value of attribute id.



6
7
8
# File 'lib/enumbler/enumble.rb', line 6

def id
  @id
end

#labelObject (readonly)

Returns the value of attribute label.



6
7
8
# File 'lib/enumbler/enumble.rb', line 6

def label
  @label
end

#label_column_nameObject (readonly)

Returns the value of attribute label_column_name.



6
7
8
# File 'lib/enumbler/enumble.rb', line 6

def label_column_name
  @label_column_name
end

Instance Method Details

#==(other) ⇒ Object



17
18
19
20
# File 'lib/enumbler/enumble.rb', line 17

def ==(other)
  other.class == self.class &&
    (other.id == id || other.enum == enum || other.label == label)
end

#attributesObject



22
23
24
25
# File 'lib/enumbler/enumble.rb', line 22

def attributes
  hash = { id: id, label_column_name => label }
  @additional_attributes.merge(hash)
end

#enumbleEnumbler::Enumble

Used to return itself from a class method.

“‘ Color.black(:enumble) #=> <Enumble:0x00007fb4396a78c8> “`

Returns:



33
34
35
# File 'lib/enumbler/enumble.rb', line 33

def enumble
  self
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


37
38
39
40
# File 'lib/enumbler/enumble.rb', line 37

def eql?(other)
  other.class == self.class &&
    (other.id == id || other.enum == enum || other.label == label)
end

#graphql_enumString

Standardizing the enum for a GraphQL schema with an uppercase string value.

Returns:

  • (String)


45
46
47
# File 'lib/enumbler/enumble.rb', line 45

def graphql_enum
  enum.to_s.upcase
end

#to_sObject



49
50
51
# File 'lib/enumbler/enumble.rb', line 49

def to_s
  enum
end