class Sjp::Parser

Parser class

Attributes

html[R]
page[R]
word[R]

Public Class Methods

new() click to toggle source
# File lib/sjp/parser.rb, line 11
def initialize
  @word, @html, @page, @hash = '', '', nil, {}
end

Public Instance Methods

allowed?() click to toggle source
# File lib/sjp/parser.rb, line 29
def allowed?
  # TODO: tests for exist and allow
  # exist? && (status != 'niedopuszczalne w grach')
  status == 'dopuszczalne w grach '
end
description() click to toggle source
# File lib/sjp/parser.rb, line 39
def description
  @page.css('p')[3].text
end
exist?() click to toggle source
# File lib/sjp/parser.rb, line 22
def exist?
  ![
    'słowo występuje tylko jako część innych haseł',
    'nie występuje w słowniku'
  ].include? status
end
html=(value) click to toggle source
# File lib/sjp/parser.rb, line 43
def html=(value)
  @html = value
  @page = Nokogiri::HTML(@html)
end
variety?() click to toggle source
# File lib/sjp/parser.rb, line 35
def variety?
  @hash['odmienność:'] == 'tak'
end
word=(text) click to toggle source
# File lib/sjp/parser.rb, line 15
def word=(text)
  @word = text
  @encoded_word = CGI.escape text
  self.html = open(path).read
  table
end

Private Instance Methods

host() click to toggle source
# File lib/sjp/parser.rb, line 50
def host
  'http://sjp.pl/'
end
path() click to toggle source
# File lib/sjp/parser.rb, line 54
def path
  "#{host}#{@encoded_word}"
end
status() click to toggle source
# File lib/sjp/parser.rb, line 58
def status
  @page.search('p').first.text
end
table() click to toggle source
# File lib/sjp/parser.rb, line 62
def table
  @page.search('table tr').each do |row|
    key, value = row.search('th').text, row.search('td').text
    @hash[key] = value
  end
end