Class: TDRB::Token
- Inherits:
-
Object
- Object
- TDRB::Token
- Defined in:
- lib/tdrb/token.rb
Constant Summary collapse
- DATETIME =
"Date / Time".freeze
- FAIL =
"Fails".freeze
- LOAD =
"Load".freeze
- METAKEY =
"Metadata Key".freeze
- METAVALUE =
"Metadata Value".freeze
- MOVEMENT =
"Movement".freeze
- NOTE =
"Note".freeze
- REP =
"Reps".freeze
- SET =
"Sets".freeze
- SUPERSET =
"Superset Movement".freeze
- TOKEN_SYMBOLS =
%i[ datetime fail load metakey metavalue movement note rep set superset ]
- ALLOWED_TYPES =
TOKEN_SYMBOLS.map { |ts| const_get(ts.upcase) }.freeze
- EOF =
"\x00".freeze
Instance Attribute Summary collapse
-
#literal ⇒ Object
readonly
Returns the value of attribute literal.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #==(t) ⇒ Object
- #===(t) ⇒ Object
-
#initialize(literal:, type:) ⇒ Token
constructor
A new instance of Token.
- #movement? ⇒ Boolean
- #performance? ⇒ Boolean
- #to_s ⇒ Object
Constructor Details
#initialize(literal:, type:) ⇒ Token
Returns a new instance of Token.
32 33 34 35 36 37 |
# File 'lib/tdrb/token.rb', line 32 def initialize(literal:, type:) raise TokenTypeError if !ALLOWED_TYPES.include?(type) @literal = literal @type = type end |
Instance Attribute Details
#literal ⇒ Object (readonly)
Returns the value of attribute literal.
3 4 5 |
# File 'lib/tdrb/token.rb', line 3 def literal @literal end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
3 4 5 |
# File 'lib/tdrb/token.rb', line 3 def type @type end |
Instance Method Details
#==(t) ⇒ Object
39 40 41 42 43 |
# File 'lib/tdrb/token.rb', line 39 def ==(t) raise TokenArgsError.new("Invalid comparison") if !t.is_a? Token literal == t.literal && type == t.type end |
#===(t) ⇒ Object
45 46 47 48 49 |
# File 'lib/tdrb/token.rb', line 45 def ===(t) raise TokenTypeError if !ALLOWED_TYPES.include?(t) type == t end |
#movement? ⇒ Boolean
51 52 53 |
# File 'lib/tdrb/token.rb', line 51 def movement? @movement ||= [MOVEMENT, SUPERSET].include?(type) end |
#performance? ⇒ Boolean
55 56 57 |
# File 'lib/tdrb/token.rb', line 55 def performance? @performance ||= [FAIL, LOAD, REP, SET].include?(type) end |
#to_s ⇒ Object
59 60 61 |
# File 'lib/tdrb/token.rb', line 59 def to_s "[#{type}] #{literal}" end |