Class: BioSyntax::Format

Inherits:
Object
  • Object
show all
Defined in:
lib/biosyntax.rb

Overview

Metadata for a supported input format.

Format objects are generated from the native extension at load time. They are immutable and comparable by native format id.

See Also:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id:, name:, description:, stateful:) ⇒ Format

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 Format.



58
59
60
61
62
63
64
# File 'lib/biosyntax.rb', line 58

def initialize(id:, name:, description:, stateful:)
  @id = Integer(id)
  @name = BioSyntax.__send__(:normalize_name, name)
  @description = String(description).freeze
  @stateful = !!stateful
  freeze
end

Instance Attribute Details

#descriptionInteger, ... (readonly)

Returns:

  • (Integer)

    native format id

  • (Symbol)

    canonical format name, such as ‘:vcf` or `:“fasta-nt”`

  • (String)

    human-readable format description



55
56
57
# File 'lib/biosyntax.rb', line 55

def description
  @description
end

#idInteger, ... (readonly)

Returns:

  • (Integer)

    native format id

  • (Symbol)

    canonical format name, such as ‘:vcf` or `:“fasta-nt”`

  • (String)

    human-readable format description



55
56
57
# File 'lib/biosyntax.rb', line 55

def id
  @id
end

#nameInteger, ... (readonly)

Returns:

  • (Integer)

    native format id

  • (Symbol)

    canonical format name, such as ‘:vcf` or `:“fasta-nt”`

  • (String)

    human-readable format description



55
56
57
# File 'lib/biosyntax.rb', line 55

def name
  @name
end

Instance Method Details

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

Parameters:

  • other (Object)

Returns:

  • (Boolean)


98
99
100
# File 'lib/biosyntax.rb', line 98

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

#hashInteger

Returns:

  • (Integer)


104
105
106
# File 'lib/biosyntax.rb', line 104

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

#inspectString

Returns:

  • (String)


109
110
111
# File 'lib/biosyntax.rb', line 109

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

#method_nameSymbol

Ruby factory method name for this format.

Hyphenated format names are exposed with underscores, for example ‘:“fasta-nt”` becomes `:fasta_nt`.

Returns:

  • (Symbol)


77
78
79
# File 'lib/biosyntax.rb', line 77

def method_name
  name.to_s.tr('-', '_').to_sym
end

#stateful?Boolean

Returns true when highlighting depends on previous lines.

Returns:

  • (Boolean)

    true when highlighting depends on previous lines



67
68
69
# File 'lib/biosyntax.rb', line 67

def stateful?
  @stateful
end

#to_hHash

Returns serializable metadata for this format.

Returns:

  • (Hash)

    serializable metadata for this format



87
88
89
90
91
92
93
94
# File 'lib/biosyntax.rb', line 87

def to_h
  {
    id: id,
    name: name,
    description: description,
    stateful: stateful?
  }
end

#to_sString

Returns canonical format name.

Returns:

  • (String)

    canonical format name



82
83
84
# File 'lib/biosyntax.rb', line 82

def to_s
  name.to_s
end