Class: Fontisan::Ucd::RangeEntry
- Inherits:
-
Object
- Object
- Fontisan::Ucd::RangeEntry
- Includes:
- Comparable
- Defined in:
- lib/fontisan/ucd/range_entry.rb
Overview
Value object representing one row in a run-length-encoded UCD index.
Sorted by first_cp. Entries within a single Index are disjoint
(no overlapping ranges).
Instance Attribute Summary collapse
-
#first_cp ⇒ Object
readonly
Returns the value of attribute first_cp.
-
#last_cp ⇒ Object
readonly
Returns the value of attribute last_cp.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #==(other) ⇒ Object (also: #eql?)
- #covers?(codepoint) ⇒ Boolean
- #hash ⇒ Object
-
#initialize(first_cp, last_cp, name) ⇒ RangeEntry
constructor
A new instance of RangeEntry.
- #size ⇒ Object
-
#to_h ⇒ Object
Compact YAML-friendly form.
Constructor Details
#initialize(first_cp, last_cp, name) ⇒ RangeEntry
Returns a new instance of RangeEntry.
14 15 16 17 18 |
# File 'lib/fontisan/ucd/range_entry.rb', line 14 def initialize(first_cp, last_cp, name) @first_cp = first_cp @last_cp = last_cp @name = name end |
Instance Attribute Details
#first_cp ⇒ Object (readonly)
Returns the value of attribute first_cp.
12 13 14 |
# File 'lib/fontisan/ucd/range_entry.rb', line 12 def first_cp @first_cp end |
#last_cp ⇒ Object (readonly)
Returns the value of attribute last_cp.
12 13 14 |
# File 'lib/fontisan/ucd/range_entry.rb', line 12 def last_cp @last_cp end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
12 13 14 |
# File 'lib/fontisan/ucd/range_entry.rb', line 12 def name @name end |
Class Method Details
.from_h(hash) ⇒ Object
49 50 51 52 53 |
# File 'lib/fontisan/ucd/range_entry.rb', line 49 def self.from_h(hash) new(hash[:first_cp] || hash["first_cp"], hash[:last_cp] || hash["last_cp"], hash[:name] || hash["name"]) end |
Instance Method Details
#<=>(other) ⇒ Object
28 29 30 |
# File 'lib/fontisan/ucd/range_entry.rb', line 28 def <=>(other) [@first_cp, @last_cp] <=> [other.first_cp, other.last_cp] end |
#==(other) ⇒ Object Also known as: eql?
32 33 34 35 36 37 |
# File 'lib/fontisan/ucd/range_entry.rb', line 32 def ==(other) other.is_a?(RangeEntry) && @first_cp == other.first_cp && @last_cp == other.last_cp && @name == other.name end |
#covers?(codepoint) ⇒ Boolean
20 21 22 |
# File 'lib/fontisan/ucd/range_entry.rb', line 20 def covers?(codepoint) codepoint >= @first_cp && codepoint <= @last_cp end |
#hash ⇒ Object
40 41 42 |
# File 'lib/fontisan/ucd/range_entry.rb', line 40 def hash [@first_cp, @last_cp, @name].hash end |
#size ⇒ Object
24 25 26 |
# File 'lib/fontisan/ucd/range_entry.rb', line 24 def size @last_cp - @first_cp + 1 end |
#to_h ⇒ Object
Compact YAML-friendly form.
45 46 47 |
# File 'lib/fontisan/ucd/range_entry.rb', line 45 def to_h { first_cp: @first_cp, last_cp: @last_cp, name: @name } end |