Class: PNGrammar
- Inherits:
-
Object
- Object
- PNGrammar
- Defined in:
- lib/pngrammar.rb
Constant Summary collapse
- URL =
"http://www-cgi.uni-regensburg.de/~brf09510/syntax.html"
Instance Attribute Summary collapse
-
#ebnf ⇒ Object
readonly
Returns the value of attribute ebnf.
-
#ua ⇒ Object
readonly
Returns the value of attribute ua.
Instance Method Summary collapse
- #image ⇒ Object
-
#initialize(file) ⇒ PNGrammar
constructor
A new instance of PNGrammar.
- #resize_image(png) ⇒ Object
- #results ⇒ Object
Constructor Details
#initialize(file) ⇒ PNGrammar
Returns a new instance of PNGrammar.
7 8 9 10 |
# File 'lib/pngrammar.rb', line 7 def initialize(file) @ebnf = File.read(file).gsub(/\n/,' ') @ua = Mechanize.new end |
Instance Attribute Details
#ebnf ⇒ Object (readonly)
Returns the value of attribute ebnf.
5 6 7 |
# File 'lib/pngrammar.rb', line 5 def ebnf @ebnf end |
#ua ⇒ Object (readonly)
Returns the value of attribute ua.
5 6 7 |
# File 'lib/pngrammar.rb', line 5 def ua @ua end |
Instance Method Details
#image ⇒ Object
12 13 14 |
# File 'lib/pngrammar.rb', line 12 def image resize_image ua.get_file(results.at('img')['src']) end |
#resize_image(png) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/pngrammar.rb', line 23 def resize_image(png) Tempfile.open('pngrammar') do |tempfile| tempfile.print png tempfile.close return begin `convert png:#{tempfile.path} -strip -trim -bordercolor White -border 10x10 -` rescue Errno::ENOENT tempfile.read end.force_encoding('binary') end end |
#results ⇒ Object
16 17 18 19 20 21 |
# File 'lib/pngrammar.rb', line 16 def results @results ||= ua.get(URL).forms.first.tap do |f| f['ssyntax'] = ebnf f['width'] = 1000 end.submit.parser end |