ruby

Is there a ruby library for checking whether a string is a valid word?

I'm trying to isolate the single words in a pdf file, but when reading the file using the pdf-reader gem the text arrives fractured, like this "A lit" "tle " "bit of tex" "t" So I'm planning to put these together using some heuristics. For this, I need a library which checks if a given string is a valid english word, like "tree".is_e...

Do all dynamic languages have the circular import issue?

For the following Python code: first.py # first.py from second import Second class First: def __init__(self): print 'Second' second.py # second.py from first import First class Second: def __init__(self): print 'Second' After creating the files and running the following from the shell: python first.py ...

Casting void* pointer in RubyCocoa

In my RubyCocoa project I am passing a block as a callback function, one of whose parameters is declared as type void *. I know that that the actual type is char *[]. My block is receiving an instance of ObjcPtr but I have been unable to access all elements within the array. The array's size is known, and passed in via another parameter....

How to use an external server with Ruby AMQP Carrot Library

I am using the Ruby AMQP Carrot library and I am trying to talk to a test RabbitMQ server on a virtual machine. The AMQP port is open on the machine but I can't get Carrot to establish an external connection. I have tried the following: Carrot.queue('message', :durable => true, :server => '192.168.162.176') Carrot.queue('messa...

calling a ruby script in c#

How do make a call to a ruby script and pass some parameters and once the script is finished return the control back to the c# code with the result? ...

Where is the best place initialize a Singleton in Rails?

Where is the best place initialize a Singleton in Rails? I am using the Carrot AMQP library in a Ruby on Rails app and I only want to initial the settings once and not on every task that is generated. I currently have it in my environment.rb and it seems to work but I am not entirely sure this is the best place. Is having Carrot initi...

Ruby alias method chain

I have a class like this class Foo attr_accessor :name end f = Foo.new f.name = "bar" and I would like it to respond to the following method chain with the name attribute so that it interfaces with another object f.baz.name == f.name Is there an easy way to return this? ...

Looking for best way to retrieve business hours from database

I'm using Ruby on Rails and I'm storing business hours like this: CREATE TABLE "business_hours" ( "id" integer NOT NULL PRIMARY KEY, "business_id" integer NOT NULL FOREIGN KEY REFERENCES "businesses", "day" integer NOT NULL, "open_time" time, "close_time" time) (which came from the thread at: http://stackoverflow.com/questions/10...

C# Array Map/Collect

In Ruby you can use the map/collect method on an array to modify it: a = [ "a", "b", "c", "d" ] a.collect! {|x| x + "!" } a #=> [ "a!", "b!", "c!", "d!" ] Is there a simple way to do this in C#? ...

Creating an HTTP POST Request with Header info using Net::HTTP in Ruby

Hi Im trying to programmatically post to an html form on the internet.I have managed to create a request with parameters in the request body but I can't figure out how to pass in Http Header attributes using the Net::Http library. Any ideas if this is possible?... Any other library that would do it for me ? res = Net::HTTP.post_form(UR...

How to test that a block was yielded to?

I have a test which needs to check if a block given to a method is being called. block = lambda { #some stuff } block.should_receive(:call) get_data_with_timeout(1, &block) def get_data_with_timeout(timeout) begin timeout(timeout) { data = get_data yield data #do stuff } rescue Tim...

How to tighten up this Ruby code?

I'm wondering how I can write this better. I was trying to use inject instead of each, but kept running into errors. Mostly I'd like to tighten up the block. Any thoughts? def to_proc levels_of_nesting = @fields.zip(@orderings) procedure = nil levels_of_nesting.each do |field, ordering| procedure = proc_for(field, ...

How to keep strings in yaml from getting converted to times

I have a yaml file which contains some times: hours: - 00:00:00 - 00:30:00 - 01:00:00 But as soon as I read them they get converted to time (in seconds), but I want them to remain as strings for a moment so i can do the conversion. Here's how I'm reading them: def daily_hours DefaultsConfig.hours.collect {|hour| ...

can I do hash.has_key?('video' or 'video2') (ruby)

or even better can I do hash.has_key?('videox') where x is '' nothing or a digit? so 'video', 'video1', 'video2' would pass the condition? of course I can have two conditions but in case I need to use video3 in the future things would get more complicated... ...

Filling a select with a series of times in increments, plus additional options

Using Ruby on Rails, I'm filling a 'select' with times using a given increment, such as every 30 minutes. Currently I'm writing out all the possibilities in a YAML file, but i feel like there's a slicker way. I'm thinking I want to provide a start_time, an end_time, an increment, and currently just one more option called 'Closed' (think...

Fastest way to get maximum value from an exclusive Range in ruby

Ok, so say you have a really big Range in ruby. I want to find a way to get the max value in the Range. The Range is exclusive (defined with three dots) meaning that it does not include the end object in it's results. It could be made up of Integer, String, Time, or really any object that responds to #<=> and #succ. (which are the only ...

Find average date from collection of dates (Ruby)

Hey guys, I have a table of guesses, within each guess is just a date. I was wondering how I would go about turning two or more dates into an average. <div id="logic"> <% foo = Date.today %> <% bar = Date.today + 10 %> <%= (foo + bar) / 2 %> Something like this, but obviously Ruby wont let me divide the two dates, any help much appr...

Selenium time outs? How to set time out limit?

Hi, I'm using Selenium Ruby client on a site with really bad performance. My scripts fails each time because of time outs. For a weeks now I am researching how time out limit can be set when using Selenium. My (Ruby) script is selenium.set_timeout(30000000000000) # does not work? selenium.open myurl In the Selenium log I can se...

Make RDoc parse unchanged files too

Hi, Is there any parameter to rdoc that tells it to include all unchanged files again, too? Calling rdoc a second (third, fourth) time, just parses the files that have been changed and index.html only shows the content of this parsed file. The other files are still available in the subdirectory but not shown. Might be an easy thing - ...

How prevent a user log in twice with the same username - using Rails Authlogic?

Hi, my question is as in the title. Thanks, Michal. ...