class Dimensional::Enum::Attributes
Attributes
attrs[R]
Public Class Methods
new( enum_attributes_hash={} )
click to toggle source
# File lib/dimensional/enum/attributes.rb, line 7 def initialize( enum_attributes_hash={} ) @attrs = enum_attributes_hash end
Public Instance Methods
id(enum_key, enum_attr_key)
click to toggle source
# File lib/dimensional/enum/attributes.rb, line 31 def id(enum_key, enum_attr_key) @attrs[enum_key.to_sym][enum_attr_key.to_sym][:id] rescue nil end
include?(key)
click to toggle source
# File lib/dimensional/enum/attributes.rb, line 11 def include?(key) @attrs.include? key end
name(enum_key, enum_attr_key)
click to toggle source
# File lib/dimensional/enum/attributes.rb, line 37 def name(enum_key, enum_attr_key) @attrs[enum_key.to_sym][enum_attr_key.to_sym][:name] rescue nil end
to_attribute_h(enum_key)
click to toggle source
# File lib/dimensional/enum/attributes.rb, line 15 def to_attribute_h(enum_key) @attrs[enum_key] end
Also aliased as: to_origin_h
to_display_h(enum_key)
click to toggle source
# File lib/dimensional/enum/attributes.rb, line 25 def to_display_h(enum_key) hash = @attrs[enum_key].each_with_object({}) do |(key, value), h| h[key] = value[:name] end end
to_json(enum_key)
click to toggle source
# File lib/dimensional/enum/attributes.rb, line 43 def to_json(enum_key) arr = [] @attrs[enum_key].each do |key, value| arr << { value: key, text: value[:name] } end JSON.unparse arr end
to_value_h(enum_key)
click to toggle source
# File lib/dimensional/enum/attributes.rb, line 19 def to_value_h(enum_key) hash = @attrs[enum_key].each_with_object({}) do |(key, value), h| h[key] = value[:id] end end