Class: Ucode::RangeEntry
- Inherits:
-
Object
- Object
- Ucode::RangeEntry
- Includes:
- Comparable
- Defined in:
- lib/ucode/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). This is a leaf value object — not a `Lutaml::Model::Serializable` model — because it has no wire shape, no nested types, and is consumed only by the YAML-backed Index. The `to_h` / `from_h` pair below is the deliberate serialization contract for the YAML file format and is exempt from the no-to_h rule by design (that rule covers model classes only).
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
Constructor Details
#initialize(first_cp, last_cp, name) ⇒ RangeEntry
Returns a new instance of RangeEntry.
18 19 20 21 22 |
# File 'lib/ucode/range_entry.rb', line 18 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.
16 17 18 |
# File 'lib/ucode/range_entry.rb', line 16 def first_cp @first_cp end |
#last_cp ⇒ Object (readonly)
Returns the value of attribute last_cp.
16 17 18 |
# File 'lib/ucode/range_entry.rb', line 16 def last_cp @last_cp end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
16 17 18 |
# File 'lib/ucode/range_entry.rb', line 16 def name @name end |
Class Method Details
.from_h(hash) ⇒ Object
52 53 54 55 56 |
# File 'lib/ucode/range_entry.rb', line 52 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
32 33 34 |
# File 'lib/ucode/range_entry.rb', line 32 def <=>(other) [@first_cp, @last_cp] <=> [other.first_cp, other.last_cp] end |
#==(other) ⇒ Object Also known as: eql?
36 37 38 39 40 41 |
# File 'lib/ucode/range_entry.rb', line 36 def ==(other) other.is_a?(RangeEntry) && @first_cp == other.first_cp && @last_cp == other.last_cp && @name == other.name end |
#covers?(codepoint) ⇒ Boolean
24 25 26 |
# File 'lib/ucode/range_entry.rb', line 24 def covers?(codepoint) codepoint >= @first_cp && codepoint <= @last_cp end |
#hash ⇒ Object
44 45 46 |
# File 'lib/ucode/range_entry.rb', line 44 def hash [@first_cp, @last_cp, @name].hash end |
#size ⇒ Object
28 29 30 |
# File 'lib/ucode/range_entry.rb', line 28 def size @last_cp - @first_cp + 1 end |
#to_h ⇒ Object
48 49 50 |
# File 'lib/ucode/range_entry.rb', line 48 def to_h { first_cp: @first_cp, last_cp: @last_cp, name: @name } end |