Class: WWWJDic::Splitter
- Inherits:
-
Object
- Object
- WWWJDic::Splitter
- Defined in:
- lib/wwwjdic/utils/splitter.rb
Overview
This class is a simple API to interact with WWWJDic Backboor Entry/API.
- Author
- Copyright
-
© 2014-2021 Marco Bresciani
- License
-
GNU General Public License version 3
Instance Method Summary collapse
-
#content ⇒ Array
The arrays of elements containing the answer.
-
#initialize(translation) ⇒ Splitter
constructor
Creates a
Splitterobject. - #lines ⇒ Object
- #message ⇒ Object
- #title ⇒ Object
- #translation ⇒ Object
Constructor Details
#initialize(translation) ⇒ Splitter
Creates a Splitter object.
- Usage
-
new_splitter = Splitter.new translation_content - Returns
-
a
Splitterobject.
44 45 46 |
# File 'lib/wwwjdic/utils/splitter.rb', line 44 def initialize(translation) @translation = translation.force_encoding('UTF-8') end |
Instance Method Details
#content ⇒ Array
Returns the arrays of elements containing the answer.
72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/wwwjdic/utils/splitter.rb', line 72 def content result = [] lines.each do |a_line| inner = {} fill_inner_data(a_line, inner) inner[:meanings] = inner[:text].split('/') if inner[:text].include? '/' result.push inner unless inner.empty? end result unless result.empty? end |
#lines ⇒ Object
62 63 64 65 66 67 68 69 |
# File 'lib/wwwjdic/utils/splitter.rb', line 62 def lines result = [] translation.each_line do |a_line| stripped_line = a_line.strip result.push stripped_line unless stripped_line.empty? end result unless result.empty? end |
#message ⇒ Object
56 57 58 59 60 |
# File 'lib/wwwjdic/utils/splitter.rb', line 56 def return Regexp.last_match(1).strip unless @translation.nil? || !/<p>(.*)<p>/m.match(@translation) Regexp.last_match(1) if @translation.nil? && /<p>(.*)<pre>/m.match(@translation) end |
#title ⇒ Object
48 49 50 |
# File 'lib/wwwjdic/utils/splitter.rb', line 48 def title Regexp.last_match(1) if %r{<TITLE>(.*)</TITLE>}.match @translation end |
#translation ⇒ Object
52 53 54 |
# File 'lib/wwwjdic/utils/splitter.rb', line 52 def translation Regexp.last_match(1).strip if %r{<pre>(.*)</pre>}m.match @translation end |