Module: Kagami

Defined in:
lib/kagami.rb,
lib/kagami/version.rb

Constant Summary collapse

VERSION =
"0.1.0"

Class Method Summary collapse

Class Method Details

.convert(line) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/kagami.rb', line 22

def convert(line)
  # Align string
  aligned_line = ljust(line)

  # Reverse
  reversed_line = reversed(aligned_line)

  # Rereverse readable words only!!!!!
  readable_line = readable(reversed_line)

  return readable_line
end

.ljust(line) ⇒ Object



9
10
11
12
# File 'lib/kagami.rb', line 9

def ljust(line)
  width = max_width(line)
  return line.lines.map{|x| x.chomp.ljust(width)}.join("\n")
end

.max_width(line) ⇒ Object



5
6
7
# File 'lib/kagami.rb', line 5

def max_width(line)
  return line.lines.map{|x| x.chomp.size}.max
end

.readable(line) ⇒ Object



18
19
20
# File 'lib/kagami.rb', line 18

def readable(line)
  return line.gsub(/(\w+(:? \w+)*)/){|s| s.reverse}
end

.reversed(line) ⇒ Object



14
15
16
# File 'lib/kagami.rb', line 14

def reversed(line)
  return line.lines.map{|x| x.chomp.reverse}.join("\n")
end

.run(source) ⇒ Object



35
36
37
# File 'lib/kagami.rb', line 35

def run(source)
  puts convert(source)
end