Class: Fontisan::Parsers::Tag

Inherits:
Object
  • Object
show all
Defined in:
lib/fontisan/parsers/tag.rb

Overview

Represents an OpenType tag (4-character identifier)

OpenType tags are four-byte identifiers used to identify tables, scripts, languages, and features. Tags are case-sensitive and padded with spaces if shorter than 4 characters.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value) ⇒ Tag

Initialize a new Tag

Parameters:

  • value (String)

    Tag value (1-4 characters)

Raises:



17
18
19
# File 'lib/fontisan/parsers/tag.rb', line 17

def initialize(value)
  @value = normalize_tag(value)
end

Instance Attribute Details

#valueObject (readonly)

Returns the value of attribute value.



11
12
13
# File 'lib/fontisan/parsers/tag.rb', line 11

def value
  @value
end

Instance Method Details

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

Compare tag with another tag or string

Parameters:

  • other (Tag, String)

    Object to compare with

Returns:

  • (Boolean)

    True if tags are equal



32
33
34
35
36
37
38
39
40
41
# File 'lib/fontisan/parsers/tag.rb', line 32

def ==(other)
  case other
  when Tag
    @value == other.value
  when String
    @value == normalize_tag(other)
  else
    false
  end
end

#hashInteger

Generate hash for use as Hash key

Returns:

  • (Integer)

    Hash value



48
49
50
# File 'lib/fontisan/parsers/tag.rb', line 48

def hash
  @value.hash
end

#to_sString

Convert tag to string

Returns:

  • (String)

    4-character tag string



24
25
26
# File 'lib/fontisan/parsers/tag.rb', line 24

def to_s
  @value
end

#valid?Boolean

Check if tag is valid (exactly 4 characters)

Returns:

  • (Boolean)

    True if tag is valid



55
56
57
# File 'lib/fontisan/parsers/tag.rb', line 55

def valid?
  @value.length == 4
end