Class: Enumbler::Enumble
- Inherits:
-
Object
- Object
- Enumbler::Enumble
- Defined in:
- lib/enumbler/enumble.rb
Overview
Class that holds each row of Enumble data.
Instance Attribute Summary collapse
-
#enum ⇒ Object
readonly
Returns the value of attribute enum.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#label ⇒ Object
readonly
Returns the value of attribute label.
-
#label_column_name ⇒ Object
readonly
Returns the value of attribute label_column_name.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #attributes ⇒ Object
-
#enumble ⇒ Enumbler::Enumble
Used to return itself from a class method.
- #eql?(other) ⇒ Boolean
-
#graphql_enum ⇒ String
Standardizing the enum for a GraphQL schema with an uppercase string value.
-
#initialize(enum, id, label: nil, label_column_name: :label, **attributes) ⇒ Enumble
constructor
A new instance of Enumble.
- #to_s ⇒ Object
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
#enum ⇒ Object (readonly)
Returns the value of attribute enum.
6 7 8 |
# File 'lib/enumbler/enumble.rb', line 6 def enum @enum end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
6 7 8 |
# File 'lib/enumbler/enumble.rb', line 6 def id @id end |
#label ⇒ Object (readonly)
Returns the value of attribute label.
6 7 8 |
# File 'lib/enumbler/enumble.rb', line 6 def label @label end |
#label_column_name ⇒ Object (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 |
#attributes ⇒ Object
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 |
#enumble ⇒ Enumbler::Enumble
Used to return itself from a class method.
“‘ Color.black(:enumble) #=> <Enumble:0x00007fb4396a78c8> “`
33 34 35 |
# File 'lib/enumbler/enumble.rb', line 33 def enumble self end |
#eql?(other) ⇒ 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_enum ⇒ String
Standardizing the enum for a GraphQL schema with an uppercase string value.
45 46 47 |
# File 'lib/enumbler/enumble.rb', line 45 def graphql_enum enum.to_s.upcase end |
#to_s ⇒ Object
49 50 51 |
# File 'lib/enumbler/enumble.rb', line 49 def to_s enum end |