Class: Wingalingding::Char

Inherits:
Object
  • Object
show all
Defined in:
lib/char.rb

Constant Summary collapse

MAX_DESCRIPTION_LENGTH =

Truncate any character descriptions exceeding this length

90

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#charObject

Returns the value of attribute char.



6
7
8
# File 'lib/char.rb', line 6

def char
  @char
end

#codeObject

Returns the value of attribute code.



6
7
8
# File 'lib/char.rb', line 6

def code
  @code
end

#descriptionObject

Returns the value of attribute description.



6
7
8
# File 'lib/char.rb', line 6

def description
  @description
end

#hexObject

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

#inspectObject



26
27
28
# File 'lib/char.rb', line 26

def inspect
  "#{char} -> #{description}"
end