Class: Enum::Base
- Inherits:
- BasicObject
- Defined in:
- lib/enum/base.rb
Class Method Summary collapse
- .all ⇒ Object
- .enum(t) ⇒ Object
- .enums(*tokens) ⇒ Object
- .exists(token) ⇒ Object
- .include?(token) ⇒ Boolean
-
.index(token) ⇒ Object
translate(enum(t)) end.
- .indexes ⇒ Object
- .inherited(child) ⇒ Object
- .values(*ary) ⇒ Object
Class Method Details
.all ⇒ Object
16 17 18 |
# File 'lib/enum/base.rb', line 16 def all history.to_a end |
.enum(t) ⇒ Object
32 33 34 35 |
# File 'lib/enum/base.rb', line 32 def enum(t) ts = t.to_sym store[index(t)] end |
.enums(*tokens) ⇒ Object
28 29 30 |
# File 'lib/enum/base.rb', line 28 def enums(*tokens) tokens.map { |token| enum(token) } end |
.exists(token) ⇒ Object
37 38 39 40 41 |
# File 'lib/enum/base.rb', line 37 def exists(token) unless history.include?(token.to_sym) raise(TokenNotFoundError, "token '#{token}'' not found in #{self}") end end |
.include?(token) ⇒ Boolean
24 25 26 |
# File 'lib/enum/base.rb', line 24 def include?(token) history.include?(token.to_sym) end |
.index(token) ⇒ Object
translate(enum(t))
end
47 48 49 50 51 52 53 |
# File 'lib/enum/base.rb', line 47 def index(token) exists(token) store.index do |h| key, value = h.first key == token.to_sym end end |
.indexes ⇒ Object
20 21 22 |
# File 'lib/enum/base.rb', line 20 def indexes (0...store.size).to_a end |
.inherited(child) ⇒ Object
6 7 8 9 10 |
# File 'lib/enum/base.rb', line 6 def inherited(child) return if self == Enum init_child_class(child) end |
.values(*ary) ⇒ Object
12 13 14 |
# File 'lib/enum/base.rb', line 12 def values(*ary) add_value(ary.first) if ary.first end |