class Lyracyst::Urban::Define

Fetches definitions and examples from Urbandictionary.com.

Public Instance Methods

get_def(search) click to toggle source

@param search [String] The word or phrase to search for.

# File lib/lyracyst/urban.rb, line 19
def get_def(search)
  label, result = 'Urban Dictionary', nil
  ur = Lyracyst::Urban.new
  result = ur.get_word(search, result)
  result = MultiJson.load(result)
  tags = result['tags']
  rtype = result['result_type']
  list = result['list']
  Lyracyst.label(label)
  print Rainbow("|Tags|#{tags}|Type|#{rtype}").bright
  st = { 'searchterm' => search }
  Lyracyst.tofile(st)
  type = { 'type' => 'urban' }
  tags = { 'tags' => tags }
  rtype = { 'result type' => rtype }
  Lyracyst.tofile(type)
  Lyracyst.tofile(tags)
  Lyracyst.tofile(rtype)
  e = Lyracyst::Urban::Define.new
  e.urban_extra(list)
end
urban_extra(list) click to toggle source

Extra reptitive tasks.

@param list [Array] List of hashes to process.

# File lib/lyracyst/urban.rb, line 43
def urban_extra(list)
  x, y = 0, list.length - 1
  while x <= y
    obj = list[x]
    author = obj['author']
    link = obj['permalink']
    defi = obj['definition']
    ex = obj['example']
    puts "|#{defi}|#{ex}|#{author}|#{link}"
    author = { 'author' => author }
    link = { 'link' => link }
    defi = { 'definition' => defi }
    ex = { 'example' => ex }
    Lyracyst.tofile(defi)
    Lyracyst.tofile(ex)
    Lyracyst.tofile(author)
    Lyracyst.tofile(link)
    x += 1
  end
end