What Ruby library can be used to select attribute using XPath, and to use it as the starting point for other XPath queries.
Example:
<root>
<add key="A" value="B" />
<add key="C" value="D" />
<add foo="E" bar="F" />
</root>
Desired code:
get_pair "//*/@key", "../@value"
get_pair "//*/@foo", "../@bar"
Expected output:
"A" "...
I need to parse some text from pdfs but the pdf formatting results in extremely unreliable spacing. The result is that I have to ignore the spaces and have a continuous stream of non-space characters.
Any suggestions on how to parse the string and put spaces back into the string by guessing?
I'm using ruby. Or should I say I'musingrub...
My code:
require 'rio'
rio('nice.jpg') < rio('http://farm4.static.flickr.com/3134/3160515898_59354c9733.jpg?v=0')
But the image downloaded is currupted. Whtat is wrong with this solution?
...
Ruby Programming control and meta combinations used for?
?a # character code
?\n # code for a newline (0x0a)
?\C-a # control a = ?A & 0x9f = 0x01
?\M-a # meta sets bit 7
?\M-\C-a # meta and control a
?\C-? # delete ...
I'm building a simple blog with comments. There is a Post model and a Comment model. Every interaction between the two works fine except for creating new comments. I'm having an issue in Rails when trying to post a new comment:
wrong number of arguments (1 for 0)
Here are the request parameters (from the stack trace):
{"commit"=>"Pos...
I have a class defined using theClass.class_eval and Object.const_set(className, theClass).
Is there any way to remove the definition of this class?
During testing I need to load different versions of the same class.
...
I need a regular expression that matches APA format references.
I currently have this:
/([A-Z][a-zA-Z\-\:\'\s\´]{3,}\, ([a-zA-Z]\.[\s|,|.]| &?){1,}){1,}\(\d\d\d\d(, [A-Z][a-z\- ]*\d\d?|)\)\.[a-zA-Z\-\:\'\s]{3,}\.[a-zA-Z\-\s]+\,[ ]*\d\d(\(\S\))*,\d+.\d+./
It only catches 10 and is fragile as hell.
I only need journal articles - not b...
I'm looking for an alternative to Google Apps for sending email from my rails app. (Google limits the number of messages you can send).
Do most people roll their own, or is their a preferred provider?
I'd love to be able to dynamically create addresses for my customers: [email protected]
...
Is it possible to call a vbscript from a ruby script? Bascially, I am creating a temp folder with a random name in my ruby script and I would like to call the vbscript and pass the name of this folder to carry out the next action.
...
I try to generate such XML using REXML
<root>
<add key='foo' value='bar'/>
</root>
But what I get is (notice that key/value order)
<root>
<add value='bar' key='foo'/>
</root>
Code:
require 'rexml/document'
include REXML
doc = Document.new
doc.add_element('root')
el = doc.root.add_element('add')
el.add_attribute('key', 'foo')
...
I watched the Creating a weblog in 15 minutes with Rails 2 and after 9 minutes in the video he shows ruby's interactive debugger, which allows you to call functions/methods from within a running script.
This goes way beyond breakpoints and looks very useful.
Is there something for PHP that gives similar functionality?
...
As I understand it, an interface is Java is intended to enforce a design by laying out methods for classes implementing the interface to fill in. Is this the idea with a Ruby module also? I see that just like with Interfaces in Java, you can't instantiate a module in Ruby.
...
I have a hash names hsh that has values that are UTF-8 encoided. For example:
hsh ={:name => some_utf_8_string, :text => :some_other_utf_8_string}
I am currently doing the following:
$KCODE="UTF8"
File.open("save.tsv","w") do{|file|
file.puts hsh.values.map{|x| x.to_s.gsub("\t",' ')}.join("\t")
}
But this croaks randomly because I...
I am looking for a good gem/plugin to convert user-uploaded audio files to different formats. One format in particular that I am interested in is converting to Apple .caf with ima4 compression for inclusion in an iPhone app.
I have been using afconvert on my mac for this so far, but I need to do it on my linux box, server-side. Ideall...
CSS Spriting can really help performance, but it's not the easiest thing to read and maintain. Are there any tools that would let me code the images individually but aggregate them up and replace the HTML with the correct subset of the montage?
I'm specifically thinking a Ruby on Rails plugin, but if there's a package for another langu...
I am trying to get call one of my classes attribute writers, but for some reason it never gets called. Here's some code that'll make this clearer:
class Test
attr_reader :test
def test=(val)
puts 'Called'
@test = val
end
def set_it(val)
test = val
end
end
obj = Test.new
obj.set_it 5
puts obj.test
=> nil
The pu...
I'm trying to use select on STDIN and a TCP socket in Ruby, but for some reason, the value returned from select never seems to match one of the choices; it looks like it's the socket that's being returned, but it doesn't match using == (or equal?). Can anyone tell me why the result returned from select doesn't match the objects I passed ...
I get an error whenever I try to use the function gets within a rake task. Is there a way to make it work?
The error says, "no such file or directory - (rake task name)"
...
I have a class that should look something like this:
class Family_Type1
@people = Array.new(3)
@people[0] = Policeman.new('Peter', 0)
@people[1] = Accountant.new('Paul', 0)
@people[2] = Policeman.new('Mary', 0)
def initialize(*ages)
for i in 0 ... @people.length
@people[i].age = ages[i]
e...
Take the two following examples:
Date.parse("02/20/2009")
Date.parse("02-20-2009")
In the first example, the order is assumed to be MM DD YYYY, but in the second example an error is raised because (I'm assuming) it tries to parse it as DD MM YYYY.
Why?
...