Class: JimBreen::CLI
- Inherits:
-
Object
- Object
- JimBreen::CLI
- Defined in:
- lib/jim_breen/cli.rb
Constant Summary collapse
- URL =
'http://www.csse.monash.edu.au/~jwb/cgi-bin/wwwjdic.cgi?11'
Class Method Summary collapse
Class Method Details
.find(text, number) ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'lib/jim_breen/cli.rb', line 22 def self.find(text, number) require 'net/http' require 'nokogiri' uri = URI(URL) response = Net::HTTP.post_form(uri, exsrchstr: text, exsrchnum: number) document = Nokogiri::HTML.parse(response.body) strip(document) end |
.help ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/jim_breen/cli.rb', line 37 def self.help puts 'Usage: jim_breen TEXT NUMBER' puts '' puts 'TEXT: Needs one or more words with which you want to find some sentences.' puts ' An example is shown like below.' puts ' $ jim_breen 楽しい' puts '' puts 'NUMBER: The number of sentences that you want to find.' puts ' This value is set 10 by default and is able to range from 5 upto 1000.' puts ' An example is below.' puts ' $ jim_breen "subject to" 50' exit end |
.start(*args) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/jim_breen/cli.rb', line 5 def self.start(*args) if args.include?('-h') || args.include?('--help') || args[0] == nil help end text = args[0] number = args[1] == nil ? 10 : args[1].to_i require 'formatador' result = find(text, number) result.gsub!(Regexp.new(text, Regexp::IGNORECASE)) do |matched| '[green]' + matched + '[/]' end Formatador.display_line(result) end |
.strip(document) ⇒ Object
32 33 34 35 |
# File 'lib/jim_breen/cli.rb', line 32 def self.strip(document) text = document.css('form#inp li').inner_text text.gsub("[T]\n", "") end |