Scrubyt wont work with windows - ruby

I am running Windows XP. I just installed the latest version of Ruby(1.9) - Hpricot, Mechanize and Scrubyt installed without any issues. I have tried to work with the simplest examples I could find to get scrubyt working. example :
require 'rubygems'
require 'scrubyt'
data = Scrubyt::Extractor.define do
fetch 'http://google.com'
title '//head/title'
end
data.to_xml.write($stdout, 1)
but, I keep getting the error :
C:/ruby/lib/ruby/gems/1.9.1/gems/scrubyt-0.4.06/lib/scrubyt.rb:1: warning: varia
ble $KCODE is no longer effective; ignored
C:/ruby/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require': no
such file to load -- jcode (LoadError)
from C:/ruby/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `
require'
from C:/ruby/lib/ruby/gems/1.9.1/gems/scrubyt-0.4.06/lib/scrubyt.rb:2:in
`<top (required)>'
from C:/ruby/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:53:in `
require'
from C:/ruby/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:53:in `
rescue in require'
from C:/ruby/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:35:in `
require' from te.rb:2:in `<main>'
I have tried several starter examples, all give the same error message. I just started with ruby today, so I can't really figure out what's going on.
Thanks!

It seems scrubyt is not ruby 1.9-ready, as jcode was used in 1.8 to deal with encoding issues. As of 1.9, ruby has a better encoding support (esp. utf-8) and therefore doesn’t need jcode anymore.
With 1.9.2:
sebastien#greystones:~/dev$ rvm 1.9.2-head
sebastien#greystones:~/dev$ ruby -v
ruby 1.9.2p94 (2010-12-08 revision 30140) [x86_64-linux]
sebastien#greystones:~/dev$ ruby -e 'require "rubygems"; require "scrubyt"'
/home/sebastien/.rvm/gems/ruby-1.9.2-head/gems/scrubyt-0.4.06/lib/scrubyt.rb:1: warning: variable $KCODE is no longer effective; ignored
<internal:lib/rubygems/custom_require>:29:in `require': no such file to load -- jcode (LoadError)
With 1.8.7:
sebastien#greystones:~/dev$ rvm 1.8.7-head
sebastien#greystones:~/dev$ ruby -v
ruby 1.8.7 (2010-12-23 patchlevel 330) [x86_64-linux]
sebastien#greystones:~/dev$ ruby -e 'require "rubygems"; require "scrubyt"'
sebastien#greystones:~/dev$
I tried to change the Scrubyt files as follows to work around that issue:
unless "".respond_to? :each_char
$KCODE = "u"
require "jcode"
end
and got further problems... So more work would need to be done to get Scrubyt to run with ruby 1.9.
FWIW, your use case is more than likely more complicated, but your example can be done with Mechanize (which Scrubyt uses internally):
require 'rubygems'
require 'mechanize'
a = Mechanize.new { |agent|
agent.user_agent_alias = 'Mac Safari'
}
a.get('http://google.com/') do |page|
puts page.title()
end

Related

What could cause a LoadError when requiring taglib-ruby in IRB?

Have gone through similar questions here, but have not been able to get this working.
I have RVM installed, and am trying to use a gemset I've set up for a Rails project to run a simple .rb file. After loading the gemset, I can load some of the gems through IRB, but not others.
1.9.2p290 :003 > require 'json'
=> true
1.9.2p290 :004 > require 'taglib-ruby'
LoadError: no such file to load -- taglib-ruby
from /Users/amoodie/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /Users/amoodie/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from (irb):4
from /Users/amoodie/.rvm/rubies/ruby-1.9.2-p290/bin/irb:16:in `<main>'
1.9.2p290 :005 > require 'dropbox-sdk'
LoadError: no such file to load -- dropbox-sdk
from /Users/amoodie/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /Users/amoodie/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from (irb):5
from /Users/amoodie/.rvm/rubies/ruby-1.9.2-p290/bin/irb:16:in `<main>'
1.9.2p290 :006 > require 'pg'
=> true
1.9.2p290 :007 > require 'rails'
=> true
All the above gems are in the same gemset. Trying to load rubygems returns false. I have no issue using accessing them through the Rails app, through.
Using the Wrong Module Names
You're probably requiring the wrong module names. For example, try require 'taglib' instead of using the name of the gem or system package. If that works, you will probably need to do something similar with the require statement for the Dropbox library, too.

LoadError on require 'tagfile/tagfile'

When I try to require the tagfile/tagfile which is part of rtaglib I get a LoadError:
$ ruby main.rb
/usr/share/rubygems/rubygems/custom_require.rb:36:in `require': cannot load such file -- tagfile/tagfile (LoadError)
from /usr/share/rubygems/rubygems/custom_require.rb:36:in `require'
from main.rb:4:in `<main>'
I installed rtaglib with
$ gem install rtaglib
Here is the top part of my main.rb:
require 'date'
require 'find'
require 'tagfile/tagfile'
None of the suggestions here (Problem with Ruby + rtaglib gem) work. taglib is installed (1.7.2)
Trying it with other gems, like sinatra, works perfectly. Does anyone know the reason I cannot load rtaglib?
Can't you just require 'tagfile'? I just tried it and it worked fine.

Ruby gem install and "No such file to load"

I'm scripting with Ruby 1.9.2dev in Backtrack 5 but I'm having some problems when try to parse html entities with the library "htmlentities".
I cannot load the library although I have installed it with gem.
I'll show you the problems I'm having in the console:
root#bt:~# gem list -d htmlentities
*** LOCAL GEMS ***
htmlentities (4.3.1)
Author: Paul Battley
Homepage: https://github.com/threedaymonk/htmlentities
Installed at: /var/lib/gems/1.9.2
A module for encoding and decoding (X)HTML entities.
root#bt:~# irb irb(main):001:0> require 'htmlentities' LoadError: no such file to load -- htmlentities
from (irb):1:in `require'
from (irb):1
from /usr/bin/irb:12:in `<main>'
This is the same problem I'm having with nokogiri. I installed the library with
gem install htmlentities
Do you have any idea why I'm having this problem?
Thank you.
EDITED:
I tried also with require 'rubygems' previously to any other require, but happens the same:
I tried require 'rubygems' but is happening the same:
irb(main):001:0> require 'rubygems'
=> false
irb(main):002:0> require 'htmlentities'
LoadError: no such file to load -- htmlentities
from (irb):2:in `require'
from (irb):2
from /usr/bin/irb:12:in `<main>'
Try to require 'rubygems' before the rest of your gems requirements.
rubygems is actually redefining the Kernel#require method to look for gems on your gempath. Whitout it ruby will just look for local/on path files.
It took me a lot but now I know how to fix it. It's about GEM_PATH.
# echo "export GEM_PATH=/var/lib/gems/1.9.2/" >> ~/.bashrc
# source ~/.bashrc
Now if I run irb:
# irb
irb(main):003:0> require 'htmlentities'
=> true
irb(main):004:0>
WOOT!

Ruby Gem "password" Does Not Seem To Install Properly

I am trying to obscure the user input (for example, when inputting a password) for a ruby script. I've tried using both the 'password' gem and 'highline/import' gem, as suggested by this stack overflow article. However, I seems to be having some issues getting the gems to work. When my script is simply:
require 'password'
require 'rubygems'
require 'activesupport'
it outputs the following errors.
C:\Users\username\Desktop>ruby test.rb
<internal:lib/rubygems/custom_require>:29:in `require': no such file to load --
activesupport (LoadError)
from <internal:lib/rubygems/custom_require>:29:in `require'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/password-1.3/lib/password.rb:1:
in `<top (required)>'
from <internal:lib/rubygems/custom_require>:33:in `require'
from <internal:lib/rubygems/custom_require>:33:in `rescue in require'
from <internal:lib/rubygems/custom_require>:29:in `require'
from test.rb:1:in `<main>'
I'm not sure that 'activesupport' is necessary; I added it because of the first error line and it hasn't seemed to help. I tried looking at the rdoc information found in the RubyGems Documentation Server and looking up each of the individual lines, but still cannot quite grasp what the problem is. I am using Ruby 1.9.2p180 on a Windows environment. Any insight would be much appreciated. Thank you in advance.
EDIT --
After following the advice of Casper, and installing the highline/import gem (gem install highline), I was able to find the following solution to my ultimate goal of obscuring password input:
require 'rubygems'
require 'highline/import'
username = ask("Enter username: ") { |x| x.echo = true }
password = ask("Enter password: ") { |x| x.echo = "*" } #assign false to echo nothing
which produces the following:
Enter username: Joe
Enter password: *********
Thanks Casper!
You need to load rubygems before you try to load any other gem files. rubygems is what enables your Ruby programs to load other gems with require:
require 'rubygems'
require 'password'
require 'activesupport'
Before you can use the password gem however you need to install it:
gem install ruby-password

Correct way to require files within a RubyGem?

I used Bundler to generate a Gem skeleton for me. Within lib/foo.rb, I have the following:
require 'foo/client'
require 'foo/other'
Those two lines are supposed to require lib/foo/client.rb and lib/foo/other.rb, respectively. It builds without a problem, but when I go to test it with irb, I get a file not found error.
ruby-1.9.2-head :003 > require 'foo'
LoadError: no such file to load -- foo/client
from /home/ethan/.rvm/rubies/ruby-1.9.2-head/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /home/ethan/.rvm/rubies/ruby-1.9.2-head/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /home/ethan/.rvm/gems/ruby-1.9.2-head/gems/foo-0.1.0/lib/foo.rb:3:in `<top (required)>'
from /home/ethan/.rvm/rubies/ruby-1.9.2-head/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /home/ethan/.rvm/rubies/ruby-1.9.2-head/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from (irb):3
from /home/ethan/.rvm/rubies/ruby-1.9.2-head/bin/irb:16:in `<main>'
ruby-1.9.2-head :004 >
What is the correct way to require files within the same Gem? There must be something simple that I'm overseeing...
If your gem is called 'foo', then all you need to do is use bundle exec:
bundle exec your-script.rb
Without bundle exec, the load paths are not set up correctly.
Using irb, you use the bundle command bundle console.
chris#chris:~/oss/pp-adaptive$ irb
irb(main):001:0> AdaptivePayments
NameError: uninitialized constant Object::AdaptivePayments
from (irb):1
from /home/chris/.rbenv/versions/1.9.2-p290/bin/irb:12:in `<main>'
irb(main):002:0>
chris#chris:~/oss/pp-adaptive$ bundle console
irb(main):001:0> AdaptivePayments
=> AdaptivePayments
irb(main):002:0>
Note that once the gem is installed on your system, you may use it without bundler.
The current directory is not in the load path in Ruby 1.9. Try one of these:
require './client'
or
require_relative 'client'
If you are in IRB itself you may have to
require "rubygems"
require "foo"
if the library is a gem. Alternatively you can require the full path of the gem, but I wouldn't advise it since rubygems does require magic so reload! works in irb ( at least it does for rails console ).

Resources