Class: Wingalingding::Char
- Inherits:
-
Object
- Object
- Wingalingding::Char
- Defined in:
- lib/char.rb
Constant Summary collapse
- MAX_DESCRIPTION_LENGTH =
Truncate any character descriptions exceeding this length
90
Instance Attribute Summary collapse
-
#char ⇒ Object
Returns the value of attribute char.
-
#code ⇒ Object
Returns the value of attribute code.
-
#description ⇒ Object
Returns the value of attribute description.
-
#hex ⇒ Object
Returns the value of attribute hex.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(line) ⇒ Char
constructor
A new instance of Char.
- #inspect ⇒ Object
Constructor Details
#initialize(line) ⇒ Char
Returns a new instance of Char.
18 19 20 21 22 23 24 |
# File 'lib/char.rb', line 18 def initialize(line) @stripped = line.strip.split(/\t/) @description = @stripped[1][0..MAX_DESCRIPTION_LENGTH] @char = @stripped[0] @hex = @stripped[2] @code = @description.match(/\(U\+[a-zA-Z0-9]+\)/).to_s end |
Instance Attribute Details
#char ⇒ Object
Returns the value of attribute char.
6 7 8 |
# File 'lib/char.rb', line 6 def char @char end |
#code ⇒ Object
Returns the value of attribute code.
6 7 8 |
# File 'lib/char.rb', line 6 def code @code end |
#description ⇒ Object
Returns the value of attribute description.
6 7 8 |
# File 'lib/char.rb', line 6 def description @description end |
#hex ⇒ Object
Returns the value of attribute hex.
6 7 8 |
# File 'lib/char.rb', line 6 def hex @hex end |
Class Method Details
.display(description) ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/char.rb', line 30 def self.display(description) chars = self.find(description) longest_description_length = chars.map{|c| c.description.size }.max table = "┏━━━━━┳━" + ("━" * longest_description_length) + "━━┓\n" chars.each{|c| table << "┃ #{c.char} ┃ #{c.description.ljust(longest_description_length)} ┃\n" } return table + "┗━━━━━┻━" + ( "━" * longest_description_length ) + "━━┛" end |
.find(description) ⇒ Object
11 12 13 14 15 16 |
# File 'lib/char.rb', line 11 def self.find(description) Scraper. character_map. find_all{|char| char =~ Regexp.new(description, "xig") }. map{|c| self.new(c)} end |
Instance Method Details
#inspect ⇒ Object
26 27 28 |
# File 'lib/char.rb', line 26 def inspect "#{char} -> #{description}" end |