Class: BioSyntax::Kind
- Inherits:
-
Object
- Object
- BioSyntax::Kind
- Defined in:
- lib/biosyntax.rb
Overview
Metadata for a semantic token kind.
Kinds describe spans returned by Highlighter#highlight. They include a TextMate-style scope and the ANSI SGR sequence used by Highlighter#colorize.
Instance Attribute Summary collapse
- #ansi_sgr ⇒ Integer, ... readonly
- #background ⇒ Integer, ... readonly
- #font_style ⇒ Integer, ... readonly
- #foreground ⇒ Integer, ... readonly
- #id ⇒ Integer, ... readonly
- #name ⇒ Integer, ... readonly
- #scope ⇒ Integer, ... readonly
Instance Method Summary collapse
- #==(other) ⇒ Boolean (also: #eql?)
- #hash ⇒ Integer
-
#initialize(id:, name:, scope:, foreground:, background:, font_style:, ansi_sgr:) ⇒ Kind
constructor
private
A new instance of Kind.
- #inspect ⇒ String
-
#to_h ⇒ Hash
Serializable metadata for this kind.
-
#to_s ⇒ String
Canonical kind name.
Constructor Details
#initialize(id:, name:, scope:, foreground:, background:, font_style:, ansi_sgr:) ⇒ Kind
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Kind.
132 133 134 135 136 137 138 139 140 141 |
# File 'lib/biosyntax.rb', line 132 def initialize(id:, name:, scope:, foreground:, background:, font_style:, ansi_sgr:) @id = Integer(id) @name = BioSyntax.__send__(:normalize_name, name) @scope = String(scope).freeze @foreground = String(foreground).freeze @background = String(background).freeze @font_style = String(font_style).freeze @ansi_sgr = String(ansi_sgr).freeze freeze end |
Instance Attribute Details
#ansi_sgr ⇒ Integer, ... (readonly)
129 130 131 |
# File 'lib/biosyntax.rb', line 129 def ansi_sgr @ansi_sgr end |
#background ⇒ Integer, ... (readonly)
129 130 131 |
# File 'lib/biosyntax.rb', line 129 def background @background end |
#font_style ⇒ Integer, ... (readonly)
129 130 131 |
# File 'lib/biosyntax.rb', line 129 def font_style @font_style end |
#foreground ⇒ Integer, ... (readonly)
129 130 131 |
# File 'lib/biosyntax.rb', line 129 def foreground @foreground end |
#id ⇒ Integer, ... (readonly)
129 130 131 |
# File 'lib/biosyntax.rb', line 129 def id @id end |
#name ⇒ Integer, ... (readonly)
129 130 131 |
# File 'lib/biosyntax.rb', line 129 def name @name end |
#scope ⇒ Integer, ... (readonly)
129 130 131 |
# File 'lib/biosyntax.rb', line 129 def scope @scope end |
Instance Method Details
#==(other) ⇒ Boolean Also known as: eql?
163 164 165 |
# File 'lib/biosyntax.rb', line 163 def ==(other) other.is_a?(Kind) && other.id == id end |
#hash ⇒ Integer
169 170 171 |
# File 'lib/biosyntax.rb', line 169 def hash [self.class, id].hash end |
#inspect ⇒ String
174 175 176 |
# File 'lib/biosyntax.rb', line 174 def inspect "#<#{self.class} name=#{name.inspect} id=#{id} scope=#{scope.inspect}>" end |
#to_h ⇒ Hash
Returns serializable metadata for this kind.
149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/biosyntax.rb', line 149 def to_h { id: id, name: name, scope: scope, foreground: foreground, background: background, font_style: font_style, ansi_sgr: ansi_sgr } end |
#to_s ⇒ String
Returns canonical kind name.
144 145 146 |
# File 'lib/biosyntax.rb', line 144 def to_s name.to_s end |