Class: BioSyntax::Kind

Inherits:
Object
  • Object
show all
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.

See Also:

Instance Attribute Summary collapse

Instance Method Summary collapse

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_sgrInteger, ... (readonly)

Returns:

  • (Integer)

    native kind id

  • (Symbol)

    canonical kind name, such as ‘:chrom`

  • (String)

    semantic scope, such as ‘“biosyntax.chrom”`

  • (String)

    foreground color as a hex string, or an empty string

  • (String)

    background color as a hex string, or an empty string

  • (String)

    font style, or an empty string

  • (String)

    ANSI SGR sequence without the surrounding escape bytes



129
130
131
# File 'lib/biosyntax.rb', line 129

def ansi_sgr
  @ansi_sgr
end

#backgroundInteger, ... (readonly)

Returns:

  • (Integer)

    native kind id

  • (Symbol)

    canonical kind name, such as ‘:chrom`

  • (String)

    semantic scope, such as ‘“biosyntax.chrom”`

  • (String)

    foreground color as a hex string, or an empty string

  • (String)

    background color as a hex string, or an empty string

  • (String)

    font style, or an empty string

  • (String)

    ANSI SGR sequence without the surrounding escape bytes



129
130
131
# File 'lib/biosyntax.rb', line 129

def background
  @background
end

#font_styleInteger, ... (readonly)

Returns:

  • (Integer)

    native kind id

  • (Symbol)

    canonical kind name, such as ‘:chrom`

  • (String)

    semantic scope, such as ‘“biosyntax.chrom”`

  • (String)

    foreground color as a hex string, or an empty string

  • (String)

    background color as a hex string, or an empty string

  • (String)

    font style, or an empty string

  • (String)

    ANSI SGR sequence without the surrounding escape bytes



129
130
131
# File 'lib/biosyntax.rb', line 129

def font_style
  @font_style
end

#foregroundInteger, ... (readonly)

Returns:

  • (Integer)

    native kind id

  • (Symbol)

    canonical kind name, such as ‘:chrom`

  • (String)

    semantic scope, such as ‘“biosyntax.chrom”`

  • (String)

    foreground color as a hex string, or an empty string

  • (String)

    background color as a hex string, or an empty string

  • (String)

    font style, or an empty string

  • (String)

    ANSI SGR sequence without the surrounding escape bytes



129
130
131
# File 'lib/biosyntax.rb', line 129

def foreground
  @foreground
end

#idInteger, ... (readonly)

Returns:

  • (Integer)

    native kind id

  • (Symbol)

    canonical kind name, such as ‘:chrom`

  • (String)

    semantic scope, such as ‘“biosyntax.chrom”`

  • (String)

    foreground color as a hex string, or an empty string

  • (String)

    background color as a hex string, or an empty string

  • (String)

    font style, or an empty string

  • (String)

    ANSI SGR sequence without the surrounding escape bytes



129
130
131
# File 'lib/biosyntax.rb', line 129

def id
  @id
end

#nameInteger, ... (readonly)

Returns:

  • (Integer)

    native kind id

  • (Symbol)

    canonical kind name, such as ‘:chrom`

  • (String)

    semantic scope, such as ‘“biosyntax.chrom”`

  • (String)

    foreground color as a hex string, or an empty string

  • (String)

    background color as a hex string, or an empty string

  • (String)

    font style, or an empty string

  • (String)

    ANSI SGR sequence without the surrounding escape bytes



129
130
131
# File 'lib/biosyntax.rb', line 129

def name
  @name
end

#scopeInteger, ... (readonly)

Returns:

  • (Integer)

    native kind id

  • (Symbol)

    canonical kind name, such as ‘:chrom`

  • (String)

    semantic scope, such as ‘“biosyntax.chrom”`

  • (String)

    foreground color as a hex string, or an empty string

  • (String)

    background color as a hex string, or an empty string

  • (String)

    font style, or an empty string

  • (String)

    ANSI SGR sequence without the surrounding escape bytes



129
130
131
# File 'lib/biosyntax.rb', line 129

def scope
  @scope
end

Instance Method Details

#==(other) ⇒ Boolean Also known as: eql?

Parameters:

  • other (Object)

Returns:

  • (Boolean)


163
164
165
# File 'lib/biosyntax.rb', line 163

def ==(other)
  other.is_a?(Kind) && other.id == id
end

#hashInteger

Returns:

  • (Integer)


169
170
171
# File 'lib/biosyntax.rb', line 169

def hash
  [self.class, id].hash
end

#inspectString

Returns:

  • (String)


174
175
176
# File 'lib/biosyntax.rb', line 174

def inspect
  "#<#{self.class} name=#{name.inspect} id=#{id} scope=#{scope.inspect}>"
end

#to_hHash

Returns serializable metadata for this kind.

Returns:

  • (Hash)

    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_sString

Returns canonical kind name.

Returns:

  • (String)

    canonical kind name



144
145
146
# File 'lib/biosyntax.rb', line 144

def to_s
  name.to_s
end