Class: BioSyntax::Format
- Inherits:
-
Object
- Object
- BioSyntax::Format
- 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.
Instance Attribute Summary collapse
- #description ⇒ Integer, ... readonly
- #id ⇒ Integer, ... readonly
- #name ⇒ Integer, ... readonly
Instance Method Summary collapse
- #==(other) ⇒ Boolean (also: #eql?)
- #hash ⇒ Integer
-
#initialize(id:, name:, description:, stateful:) ⇒ Format
constructor
private
A new instance of Format.
- #inspect ⇒ String
-
#method_name ⇒ Symbol
Ruby factory method name for this format.
-
#stateful? ⇒ Boolean
True when highlighting depends on previous lines.
-
#to_h ⇒ Hash
Serializable metadata for this format.
-
#to_s ⇒ String
Canonical format name.
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
#description ⇒ Integer, ... (readonly)
55 56 57 |
# File 'lib/biosyntax.rb', line 55 def description @description end |
#id ⇒ Integer, ... (readonly)
55 56 57 |
# File 'lib/biosyntax.rb', line 55 def id @id end |
#name ⇒ Integer, ... (readonly)
55 56 57 |
# File 'lib/biosyntax.rb', line 55 def name @name end |
Instance Method Details
#==(other) ⇒ Boolean Also known as: eql?
98 99 100 |
# File 'lib/biosyntax.rb', line 98 def ==(other) other.is_a?(Format) && other.id == id end |
#hash ⇒ Integer
104 105 106 |
# File 'lib/biosyntax.rb', line 104 def hash [self.class, id].hash end |
#inspect ⇒ String
109 110 111 |
# File 'lib/biosyntax.rb', line 109 def inspect "#<#{self.class} name=#{name.inspect} id=#{id} stateful=#{stateful?}>" end |
#method_name ⇒ Symbol
Ruby factory method name for this format.
Hyphenated format names are exposed with underscores, for example ‘:“fasta-nt”` becomes `:fasta_nt`.
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.
67 68 69 |
# File 'lib/biosyntax.rb', line 67 def stateful? @stateful end |
#to_h ⇒ Hash
Returns 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_s ⇒ String
Returns canonical format name.
82 83 84 |
# File 'lib/biosyntax.rb', line 82 def to_s name.to_s end |