Class: Alc::Cmd::Eijiro
- Inherits:
-
Thor::Shell::Color
- Object
- Thor::Shell::Color
- Alc::Cmd::Eijiro
- Defined in:
- lib/alc-cmd/eijiro.rb
Constant Summary collapse
- BASE_URI =
"http://eow.alc.co.jp/"
- CHAR_CODE =
"/UTF-8/"
Instance Method Summary collapse
-
#get_meanings ⇒ Object
:nodoc:.
-
#get_search_assistances ⇒ Object
:nodoc:.
-
#get_titles ⇒ Object
:nodoc:.
-
#initialize ⇒ Eijiro
constructor
:nodoc:.
-
#make_query_from_words(words) ⇒ Object
:nodoc:.
-
#make_uri_from_words(words) ⇒ Object
:nodoc:.
-
#search(words) ⇒ Object
:nodoc:.
Constructor Details
#initialize ⇒ Eijiro
:nodoc:
10 11 12 |
# File 'lib/alc-cmd/eijiro.rb', line 10 def initialize() #:nodoc: @agent = Mechanize.new end |
Instance Method Details
#get_meanings ⇒ Object
:nodoc:
52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/alc-cmd/eijiro.rb', line 52 def get_meanings #:nodoc: meanings = Array.new @agent.page.search('li div').each do |div| lis = div.search('li') if lis.size != 0 meanings << lis.inject('') { |text, li| text + " " + li.inner_text + "\n" } else meanings << " " + div.inner_text end end return meanings end |
#get_search_assistances ⇒ Object
:nodoc:
38 39 40 41 42 43 44 |
# File 'lib/alc-cmd/eijiro.rb', line 38 def get_search_assistances #:nodoc: assistances = [] @agent.page.search('div.sas strong').map do |h| assistances << h.inner_text.chomp("\t\t\t\t\t\t") end assistances end |
#get_titles ⇒ Object
:nodoc:
46 47 48 49 50 |
# File 'lib/alc-cmd/eijiro.rb', line 46 def get_titles #:nodoc: return @agent.page.search('li span.midashi').map do |midashi| inner_text = midashi.inner_text end end |
#make_query_from_words(words) ⇒ Object
:nodoc:
34 35 36 |
# File 'lib/alc-cmd/eijiro.rb', line 34 def make_query_from_words(words) #:nodoc: return words.map { |param| URI.encode(param) }.join('+') end |
#make_uri_from_words(words) ⇒ Object
:nodoc:
30 31 32 |
# File 'lib/alc-cmd/eijiro.rb', line 30 def make_uri_from_words(words) #:nodoc: return BASE_URI + make_query_from_words(words) + CHAR_CODE end |
#search(words) ⇒ Object
:nodoc:
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/alc-cmd/eijiro.rb', line 14 def search(words) #:nodoc: @agent.get(make_uri_from_words(words)) @words = words result = "" get_search_assistances.each do |assistance| result << set_color(assistance, :green) + "\n" end meanings = get_meanings get_titles.each_with_index do |title, index| result << set_color(title, :yellow) + "\n" result << set_color(meanings[index]) + "\n" end result end |