ruby

gsub ASCII code characters from a string in ruby

Hi, I am using nokogiri to screen scrape some HTML. In some occurrences, I am getting some weird characters back, I have tracked down the ASCII code for these characters with the following code: @parser.leads[0].phone_numbers[0].each_byte do |c| puts "char=#{c}" end The characters in question have an ASCII code of 194 and 1...

Intelligent date range parsing of human input?

Has anyone come across a script / cl app written in any language that handles the parsing of human-entered dates well? I'd love to be able to parse, for example: "3 to 4 weeks" "2 - 3 days" "3 weeks to 2 months" ...

Why getting error: Object#id will be deprecated; use Object#object_id

On my local development rails environment, I am able to check the output from a SOAP call just fine. I can use response.id to get the value from this packet displayed using the .inspect method: #<SOAP::Mapping::Object:0x15702d0c0604 {}id="dd26ce5f-0cfd-9bbb-3485-4c64c9d6378 4" {}error=#<SOAP::Mapping::Object:0x15702d0bf6f0 {}number="0"...

Is there a way to decode q-encoded strings in Ruby?

I'm working with mails, and names and subjects sometimes come q-encoded, like this: =?UTF-8?Q?J=2E_Pablo_Fern=C3=A1ndez?= Is there a way to decode them in Ruby? It seems TMail should take care of it, but it's not doing it. ...

gsub non ASCII character in Ruby

Hi, I am trying to replace a non ASCII character from a string with the following code: string.gsub(194.chr,'') When I do this, I get the following error: RegexpError: premature end of regular expression: /�/ Can anyone tell me how to achieve this? Thanks Paul ...

Problems with routing and path

Hello, I am new to rails and I have a weird problem i don't understand... I have created a basic application with only one controller. this controller is name routes (for testing purpose...) and it contains index, new and edit actions. I have added a resource in the routes.rb file: map.resources :routes The problem I have is when i...

Converting PDFs to be viewed in any browser

I currently use a PDF-to-Flash to allow for users to flip thru pages of uploaded PDFs. However, with so many using iPhones/iPads I would like to switch this to a solution which works with any browser. The site is developed in Ruby on Rails and I have looked into using pdf-toolkit and rmagick to convert the PDFs to images but it's not en...

How to uniquify an array in Ruby?

I am aware of ".uniq" method but it is not working here. I pushed Mechanize link instances in an array and applied it but it is not removing duplicates. Here is the array.. #<Mechanize::Page::Link "2" "/inquiry/inquiry-results.jsp?d-16544-p=2&middleName=&firstName=&lastName=JOHN">, #<Mechanize::Page::Link "3" "/inquiry/inquiry-results.j...

Making sense of "/dev/video" ouput.

I've tried writing a simple application thats supposed to detect pixel differences from the /dev/video device. Like motion does. I don't know how the /dev/video device works, so most of it was guesswork. What I found is that it seems like the data ( from the specific webcam ) can be divided into sections of 8192 bytes. I assume each rep...

Why does Mac OS X come with ruby/rails?

Why does Mac OS X come with ruby and ruby on rails pre-installed? Does the OS actually use it at all? Can I update my Ruby, Rails or Gem versions safely without something spitting the dummy? ...

Get calendar events from Calendar (possibly using ActiveDirectory)

Hi, I need to start extracting events in a microsoft calendar. I've never done this before, so just want pointing in the right direction. Does anyone know if this is possible using Active directory? Anyone have any examples of where this has been done before? Thanks, Ian ...

What's the best way to write Resque-related specs in RSpec?

What's the best way to write Resque-related specs in RSpec without stubbing the former? We currently use the following helper: @dir = File.dirname(File.expand_path(__FILE__)) def start_redis `redis-server #{@dir}/redis-test.conf` Resque.redis = "localhost:9736" end def stop_redis `rm -f #{@dir}/dump.rdb` pid = `ps -A -o pid,c...

Sass (Ruby CSS compressor) absolute path parameters on Windows

I'm using sass (from haml-edge) for processing css files, and it crashes on absolute paths as parameters: K:\sass>sass.bat k:/sass/css/*.scss k:/sass/css/*.css --trace d:/Programs/Ruby/lib/ruby/gems/1.9.1/gems/haml-edge-3.1.62/lib/sass/files.rb:23:in `read': No such file or directory - k (Errno::ENOENT) from d:/Programs/Ruby/lib/ru...

String constants in Ruby

In Python >>> import string >>> string.uppercase 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' or >>> string.digits '0123456789' Is there a way to use a string constant in Ruby? ...

How to add trailing slash if needed with gsub

I'm trying to add trailing slash if needed: a = "/var/www" a.gsub... I dont know how to do it. ...

Rotate Bits Right operation in Ruby

Hi all, Is there a Rotate Bits Right in Ruby ? Or how can I do that please. Thanks ...

Trying to install a ruby gem on Mac OSX gives me an error: "Failed to build gem native extension."

I've been trying to install mongrel on my Mac OS X (Leopard) and it errors out with the message "Failed to build em native extension". What am I missing in my system? The versions of Ruby and gems that I am using are 1.8.7 and 1.3.3 respectively. ...

RoR: clear_link per record

I'm talking half-ruby half-english in the following paragraph I have Persons and I have 'Pet's. Person has_many Pet. I have a table of Persons displayed with pets included in the cell, like: def pets_column(record) if record.pets.count == 0 'no pets' else record.pets.collect{|p| html_escape(p.to_label) }.join('<br />') en...

Why arent fields getting detected in Ruby Mechanize?

http://casesearch.courts.state.md.us/inquiry/inquirySearchParam.jis agent = Mechanize.new form = agent.get("http://casesearch.courts.state.md.us/inquiry/inquiry-index.jsp").forms.first form.checkbox_with(:name => /disclaimer/).check page = form.submit The above code submits the discalimer in the above website. Now after submit...

Converting ruby array to array of consecutive pairs

What is the easiest way to convert a ruby array to an array of consecutive pairs of its elements? I mean: x = [a, b, c, d] → y = [[a, b], [c, d]] ...