Class: Han::CLI

Inherits:
Thor::Group
  • Object
show all
Defined in:
lib/han.rb

Instance Method Summary collapse

Instance Method Details

#processObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/han.rb', line 14

def process
  uri = URI(URI::encode("http://www.zdic.net/sousuo/?q=#{character}"))
  res = Net::HTTP.get_response(uri)

  doc = Nokogiri::HTML(open("http://www.zdic.net#{res['location']}"))

  lines = doc.css('p').to_a
  lines.shift
  char = lines.shift
  trad = traditional(lines)
  
  if trad
    say "#{char.content[2..-1]}#{trad}"
  else
    say "#{char.content[2..-1]}"
  end

  py = lines.shift
  say py.content.split[0]
  say
  lines.each { |l| say l.content[1..-1] if l.content[0] == ' ' }
end