Class: Yosina::Char
- Inherits:
-
Object
- Object
- Yosina::Char
- Defined in:
- lib/yosina/char.rb
Overview
Represents a character with metadata for transliteration
Instance Attribute Summary collapse
-
#c ⇒ Object
Returns the value of attribute c.
-
#offset ⇒ Object
Returns the value of attribute offset.
-
#source ⇒ Object
Returns the value of attribute source.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(c:, offset:, source: nil) ⇒ Char
constructor
Initialize a new character.
- #inspect ⇒ Object
-
#sentinel? ⇒ Boolean
Check if the character is a sentinel (empty character).
- #to_s ⇒ Object
-
#transliterated? ⇒ Boolean
Check if the character has been transliterated.
-
#with_offset(offset) ⇒ Char
Create a new Char with a different offset.
Constructor Details
#initialize(c:, offset:, source: nil) ⇒ Char
Initialize a new character
rubocop:disable Naming/MethodParameterName
14 15 16 17 18 |
# File 'lib/yosina/char.rb', line 14 def initialize(c:, offset:, source: nil) @c = c @offset = offset @source = source end |
Instance Attribute Details
#c ⇒ Object
Returns the value of attribute c.
6 7 8 |
# File 'lib/yosina/char.rb', line 6 def c @c end |
#offset ⇒ Object
Returns the value of attribute offset.
6 7 8 |
# File 'lib/yosina/char.rb', line 6 def offset @offset end |
#source ⇒ Object
Returns the value of attribute source.
6 7 8 |
# File 'lib/yosina/char.rb', line 6 def source @source end |
Instance Method Details
#==(other) ⇒ Object
51 52 53 54 55 |
# File 'lib/yosina/char.rb', line 51 def ==(other) return false unless other.is_a?(Char) c == other.c && offset == other.offset && source == other.source end |
#inspect ⇒ Object
61 62 63 |
# File 'lib/yosina/char.rb', line 61 def inspect "#<Yosina::Char c=#{c.inspect} offset=#{offset} source=#{source&.inspect}>" end |
#sentinel? ⇒ Boolean
Check if the character is a sentinel (empty character)
24 25 26 |
# File 'lib/yosina/char.rb', line 24 def sentinel? @c.empty? end |
#to_s ⇒ Object
57 58 59 |
# File 'lib/yosina/char.rb', line 57 def to_s c end |
#transliterated? ⇒ Boolean
Check if the character has been transliterated
39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/yosina/char.rb', line 39 def transliterated? c = self loop do s = c.source break if s.nil? return true if c.c != s.c c = s end false end |