ruby

ImageMagick convert error (Wrong JPEG library version: library is 62, caller expects 70)

Looks like it is reading the wrong jpeg ibrary, but I have jpeg 7 installed. How do i tell ImageMagick to look up the right JPEG library version(I don't care 62 or 70 as long as it works). here is the instruction i am following ...

Ruby: Send logger messages to a string variable?

I have a small framework that is logging some info and debug messages using the Logger object built into ruby. At run time, this works great. At unit test time (using rspec if it matters...) i would like to dump the logged messages to an in memory string variable. What's the easiest way to go about doing this? I was considering a monkey...

Ruby initialize method: setting instance variable with a hash key

Hello, I am facing a undefined local variable or method error when initializing the following in ruby: class Model attr_accessor :var1, :var2, :state def initialize (x, y, key) @var1 = x @var2 = y @state = every_state[:key] #this line produces the error @every_state = { :A => SateA.new, :B => StateB.new, :C =>...

Nokogiri: how to search for certain element, and output the full traverse ?

using nokogiri, i want to find <p class="main"> Some text here...</p> from an html document, and then output the location as below or something that shows the tree html > body > div class = "body" > p class= "main " ...

Ruby Style: should initialize take a file with data or just the raw data as parameters

Hello, I was curious if anyone had insight on what is the best way for an object to load data from a file in Ruby. Is there a convention? There are two ways I can think of accomplishing this: Have the initialize method accept a path or file and parse the data within the initialize method, setting the object variables as well. Have th...

iterating over each character of a String in ruby 1.8.6 (each_char)

Hello, I am new to ruby and currently trying to operate on each character separately from a base String in ruby. I am using ruby 1.8.6 and would like to do something like: "ABCDEFG".each_char do|i| puts i end This produces a undefined method `each_char' error. I was expecting to see a vertical output of: A B C D ..etc Is the each...

there's PyQuery....is there one for Ruby ?

you guys know Pyquery i was wondering if theres one for Ruby ...

nokogiri : how to select an element with its text content via CSS not xpath?

http://stackoverflow.com/questions/1474688/nokogiri-how-to-select-nodes-by-matching-text can do thsi via Xpath however, i am looking for a way to do a CSS select by matching the text of element. PyQuery, PHPQuery can do this. Isnt there a Jquery API lib for ruby ? ...

Ruby: How to evalulate multiple methods per send command?

Let's say I have an XML::Element...I want to do something like: my_xml_element.send("parent.next_sibling.next_sibling") ...

Ruby Constructors and Exceptions

New to Ruby, and I'm trying to figure out what idiom to use to restrict some integer values to the constructor of a class. From what I've done so far, if I raise an exception in initialize(), the object is still created but will be in an invalid state (for example, some nil values in instance variables). I can't quite see how I'm suppo...

Instance Eval Within Block

I have a Builder class that lets you add to one of it's instance variables: class Builder def initialize @lines = [] end def lines block_given? ? yield(self) : @lines end def add_line( text ) @lines << text end end Now, how do I change this my_builder = Builder.new my_builder.lines { ...

how to get xpath of text between <br> or <br /> ?

</div> apple <br> banana <br/> watermelon <br> orange Assuming the above, how is it possible to use Xpath to grab each fruit ? Must use xpath of some sort. should i use substring-after(following-sibling...) ? EDIT: I am using Nokogiri parser. ...

ruby logging convenience method

I would like a ruby method "show" which does this: anyobject.show the output of the call would be: anyvar => the pp string of the object Something close , but not quite is : p "any_var => #{any_var.pretty_inspect}" Since you have to type "anyvar" out to accomplish that. ...

Limited matrices in Ruby

How come the Matrix class has no methods to edit it's vectors and components? It seems like everything inside a matrix could be read but not written. Am I mistaking? Is there some third-party elegant Matrix-like class which would allow to delete rows and intentionally edit them? Please, notice me if there are no such - I will stop searc...

When (if) to consolidate ActiveRecord migrations?

As I move through the iterations on my application*(s) I accumulate migrations. As of just now there are 48 such files, spanning about 24 months' activity. I'm considering taking my current schema.rb and making that the baseline. I'm also considering deleting (subject to source control, of course) the existing migrations and creating a...

How to implement cookie support in ruby net/http?

Hello, I'd like to add cookie support to a ruby class utilizing net/http to browse the web. Cookies have to be stored in a file to survive after the script has ended. Of course I can read the specs and write some kind of a handler, use some cookie.txt format and so on, but it seems to mean reinventing the wheel. Is there a better way to ...

Ruby: Shortest/most idiomatic way of determining whether a variable is any one of a list of values

This seems a ridiculously simple question to be asking, but what's the shortest/most idiomatic way of rewriting this in Ruby? if variable == :a or variable == :b or variable == :c or variable == :d # etc. I've previously seen this solution: if [:a, :b, :c, :d].include? variable but this isn't always functionally equivalent - I beli...

Grab PDF file from website?

I maintain a website showing my university group's publications. I have written a quick and dirty Ruby script to parse a CSV file containing this data (which I grab manually from ISI Web of Science website), and present it in a nice format in HTML. There is no direct link to a PDF file in the CSV file. Instead, there is information whi...

rails: put and interruption in before filter

I want a before filter like "must_have_permission_to_write" that when called if user hasn't permission to write renders a message saying "you can't do that!" and return. Problem is I'm getting "can only render or redirect once per action" of course... how can I stop the execution in the before filter? thanks ...

Ruby (not Rails) giving a NoMethodError when using find()

I have a couple of scripts that interact with a MySQL database using ActiveRecord without the rest of the Rails package (although I have the complete Rails gem installed). However, trying to use these classes lately has been giving me the NoMethodError when I try to call find() on my ActiveRecord-descended class. The class code is amazi...