class Lyracyst::Wordnik::Origin
Fetches etymologies from Wordnik
.
Public Instance Methods
get_et(search, params)
click to toggle source
@param search [String] The word or phrase to search for. @param params [Hash] The search parameters to use.
# File lib/lyracyst/wordnik/origin.rb, line 10 def get_et(search, params) func, result = 'etymologies', nil etymology = Lyracyst::Wordnik.new e = Lyracyst::Wordnik::Origin.new result = etymology.get_word(search, func, params, result) if result != nil && result != '[]' result = MultiJson.load(result) type = { 'type' => 'etymology' } st = { 'searchterm' => search } Lyracyst.tofile(st) Lyracyst.tofile(type) e.origin_extra(result) else puts 'Wordnik failed to fetch word info.' end end
origin_extra(result)
click to toggle source
Extra repetitive tasks.
@param result [Array] List of hashes to process.
# File lib/lyracyst/wordnik/origin.rb, line 29 def origin_extra(result) ee = Lyracyst::Wordnik::Origin.new a, b, label = 0, result.length - 1, 'Etymology' while a <= b xml = result[a] xml = MultiXml.parse(xml) root = xml['ety'] content, ets, er = root['__content__'], root['ets'], root['er'] root = { 'root' => content } Lyracyst.tofile(root) Lyracyst.label(label) print "#{content}|" if ets != nil ee.origin_extra2(ets) else puts '' end if er != nil print '|' ee.origin_extra2(er) else puts '' end a += 1 puts '' end end
origin_extra2(obj)
click to toggle source
Extra repetitive tasks.
@param obj [Hash] Object
hash to process.
# File lib/lyracyst/wordnik/origin.rb, line 59 def origin_extra2(obj) a, b, container = 0, obj.length - 1, [] while a <= b if b == 0 content = obj['__content__'] container.push content else content = obj[a] container.push content['__content__'] end a += 1 end print "#{container.join('|')}" node = { 'node' => container.join(',') } Lyracyst.tofile(node) end